json

浏览:1277 发布日期:2015/06/17 分类:求助交流 关键字: ajax接收json
HTML页面:
<html>
<head>
<title>测试页面</title>
<script src="/Public/static/jquery.js" content-type='utf-8'></script>
</head>
<script type="text/javascript">
$.ajax({
type: "get",
url:"index.php?s=/Home/restful/cg",
cache : false,
async : false,
dataType: "json",
success: function(data){
$.each(data, function(key,val){

alert(val.name);
})

}
})

</script>
<body>
<p>this is the information</p>
<div class="mydiv"></div>

</body>
</html>


PHP页面:

Public function cg() {
switch ($this->_method){
case 'get': // get请求处理代码
//获取商品父级类型
$where['pid']=0;
$cg=M('cg')->where($where)->select();
$json_str=json_encode($cg);

echo $json_str;
break;
}
}


html页面ajax成功接收到了返回的信息(json格式),alert()成功弹出信息。
我是想将信息显示在html页面上,不是在alert()中。该怎么写呢。
最佳答案
评论() 相关
后面还有条评论,点击查看>>