Why does the prompt result after running is [Object Object],[object object] instead of specific data?
The result should be this way. [{title: ' 3333333333333 '}, {title: ' 3333333333333 '}]
And then I tried again.
alert(obj.title)So hint undefined why is this?
$res=$xiao->field("title")->select();$this->ajaxReturn($res);ajax("{:U('zhuye/zhuye')}",oV1,function(str){ var obj = eval("("+str+")"); alert(obj);});
Reply content:
Why does the prompt result after running is [Object Object],[object object] instead of specific data?
The result should be this way. [{title: ' 3333333333333 '}, {title: ' 3333333333333 '}]
And then I tried it again. This alert(obj.title) is the hint undefined why?
$res=$xiao->field("title")->select();$this->ajaxReturn($res);ajax("{:U('zhuye/zhuye')}",oV1,function(str){ var obj = eval("("+str+")"); alert(obj);});
Use jquery to solve your problem, read the documentation.
obj is an array of two objects, not an object
Give it a tryalert(obj[0].title); alert(obj[1].title);
Give it a try. It's supposed to be the type of array you're talking about.
var obj = JSON.parse(str)alert(obj);
Add a return data type to it, Datatype:json.
Print it out to see ....
Should be
alert(obj[0].title);
Your data is already an object. When you are eval or json.prase, the call is obj.tostring ();
You can see the difference between JavaScript literal objects and JSON to know what the problem is.
The return type is not in JSON format.