首页 > 后端开发 > php教程 > 求解php传数组js解用.该怎么解决

求解php传数组js解用.该怎么解决

WBOY
发布: 2016-06-13 13:42:01
原创
830 人浏览过

求解php传数组js解用....
js异步请求php文件返回数组echo js_encode($list);
数组输出为:function(data){alert(data)}
{"1":{"id":54,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=new&act=newlist"},"2":{"id":46,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=newlist"},"3":{"id":56,"neme":"\u5212","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=\u611f\u5230"},"4":{"id":58,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=space&mod=welcome&act=\u548c"},"5":{"id":87,"neme":"\u7ba1\u7406\u5458","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=come&act=newlist"},"6":{"id":54,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=\u8c01\u7684"}}
但for循环输出时却发现被单解了....代码如下.

function(data){
alert(data);
  alert(data.length);//弹出为692
for(var i=0;i alert(data[i]);//弹出为未定义
}

但是我把弹出的数组复制符值却可以..
如下:
var data1={"1":{"id":54,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=new&act=newlist"},"2":{"id":46,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=newlist"},"3":{"id":56,"neme":"\u5212","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=\u611f\u5230"},"4":{"id":58,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=space&mod=welcome&act=\u548c"},"5":{"id":87,"neme":"\u7ba1\u7406\u5458","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=come&act=newlist"},"6":{"id":54,"neme":"sdfa","0":"pic","1":"http:\/\/localhost\/xin\/index.php?app=home&mod=welcome&act=\u8c01\u7684"}}
..........................................................
这是怎么回事?

------解决方案--------------------
php 的 echo js_encode($list);
在 js 中得到的是字符串,你需要将其转换成 js 的对象。
最简答的方法就是 eval

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板