PHP返回 json_encode JQ JSON 接受 求高手
PHP代码:
$group_rs=select_spell("article_widget_article_channel","*","site_id=$zd",'nodepath');
if(!empty($group_rs))
{
foreach($group_rs as $i=>$rs)
{
$ary[$i] = array("id" =>$rs['id'],"nodepath" =>$rs['nodepath']);
}
}
echo json_encode($ary);
页面显示:
[{"id":"1","nodepath":"001"},{"id":"2","nodepath":"001001"},{"id":"3","nodepath":"002"},{"id":"4","nodepath":"002001"},{"id":"7","nodepath":"004"},{"id":"8","nodepath":"004001"},{"id":"9","nodepath":"004002"}]
JS 代码:
function getleft(id){
zz="zid="+id;
jQuery.ajax({
type:"get",
url:"manage/tz_left.php",
data:zz,
dataType:"json",
beforeSend: function(){
//
},
success:function(msg){
jQuery.each(msg, function(i,n){
alert(n.id);
alert(n.nodepath);
});
} ,
complete: function(XMLHttpRequest, textStatus){
alert(XMLHttpRequest);
alert(textStatus);
}
});
}
然后报错了
小弟刚学PHP 跟JQ 不知道这个哪里错了?
另外
类似这种直接赋值的写法
/*$id=array();
$id[0]["id"]='1';
$id[0]["name"]='张三';
$id[0]["type"]='111111';
$id[1]["id"]='2';
$id[1]["name"]='李四';
$id[1]["type"]='2222';
echo json_encode($id);*/
是可以接受到的