jquery ajax和php实现返回值 json类型

js页面
$.ajax({
   type: “POST”,
   dataType: ‘json’,
   url: “add_vote.php”,
   data: “touid=”+uid+”&tousername=”+username,
   success: function(msg){
   //json解析方法一
      var dataObj=eval("("+msg+")");//转换为json对象 
      alert(dataObj.goods_list);//输出root的子对象数量 
   //json解析方法二
      var result = JSON.parse(msg);
      alert(result[key]);
      方法二在IE6.7下需要加载js文件才行。json2下载
   }
});
php页面
$arrall = array(1=>”王辉”,2=>”wanghui”);
echo json_encode($res);
原文地址:https://www.cnblogs.com/whlives/p/3881041.html