Why does the data returned by Javascript-ajax prompt object?

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.