Heim  >  Artikel  >  Backend-Entwicklung  >  javascript - ajax返回的数据为什么提示object?

javascript - ajax返回的数据为什么提示object?

WBOY
WBOYOriginal
2016-09-29 09:33:021015Durchsuche

运行后 为什么提示的结果是[object Object],[object Object] 而不是具体的数据呢?
这个结果应该是这样才对[{title: "3333333333333"}, {title: "3333333333333"}]
然后我又试了一下alert(obj.title) 这样提示undefined 这是为什么?

<code>$res=$xiao->field("title")->select();
$this->ajaxReturn($res);


ajax("{:U('zhuye/zhuye')}",oV1,function(str){
   var obj = eval("("+str+")");
   alert(obj);
});</code>

回复内容:

运行后 为什么提示的结果是[object Object],[object Object] 而不是具体的数据呢?
这个结果应该是这样才对[{title: "3333333333333"}, {title: "3333333333333"}]
然后我又试了一下alert(obj.title) 这样提示undefined 这是为什么?

<code>$res=$xiao->field("title")->select();
$this->ajaxReturn($res);


ajax("{:U('zhuye/zhuye')}",oV1,function(str){
   var obj = eval("("+str+")");
   alert(obj);
});</code>

用jquery解决你的问题,具体看文档吧

obj是两个Object的Array 不是Object

试试alert(obj[0].title); alert(obj[1].title);

试试. 出来的应该就是 你说的那种数组形式.

<code>var obj = JSON.parse(str)

alert(obj);</code>

加一个返回数据类型就可以了,dataType:json

打印出来看。。。。

应该是

<code>   alert(obj[0].title);
</code>

你的数据已经是Object了。你在eval或JSON.prase时,调用的是 obj.toString();

你去看看JavaScript 字面量对象和json的区别就知道是什么问题了。

返回类型不是json格式吧

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn