After running, why does the prompt result show [object Object], [object Object] instead of specific data?
This result should be like this [{title: "3333333333333"}, {title: "3333333333333"}]
Then I tried it againalert(obj.title)
It prompts undefined. Why is this?
<code>$res=$xiao->field("title")->select(); $this->ajaxReturn($res); ajax("{:U('zhuye/zhuye')}",oV1,function(str){ var obj = eval("("+str+")"); alert(obj); });</code>
After running, why does the prompt result show [object Object], [object Object] instead of specific data?
This result should be like this [{title: "3333333333333"}, {title: "3333333333333"}]
Then I tried it againalert(obj.title)
It prompts undefined. Why is this?
<code>$res=$xiao->field("title")->select(); $this->ajaxReturn($res); ajax("{:U('zhuye/zhuye')}",oV1,function(str){ var obj = eval("("+str+")"); alert(obj); });</code>
Use jquery to solve your problem, please read the documentation for details
obj is an Array of two Objects, not an Object
Tryalert(obj[0].title); alert(obj[1].title);
Try it. What comes out should be the array form you mentioned.
<code>var obj = JSON.parse(str) alert(obj);</code>
Just add a return data type, dataType:json
Print it out and read it. . . .
should be
<code> alert(obj[0].title); </code>
Your data is already an Object. When you are eval or JSON.prase, you are calling obj.toString();
You will know what the problem is if you look at the difference between JavaScript literal objects and json.
The return type is not in json format, right?