$.ajax receives JSON, returns ERROR__JS

Source: Internet
Author: User

Please enter http://blog.csdn.net/hzz780/article/details/42124607 using PHP

In other words, last week, the page local JSON data debugging handed to the program, he told me to always return the error, not executed. I went to the interview with my girlfriend 5 last week and didn't come back to deal with it. Today a deal, found the original problem is so, before writing a http://blog.csdn.net/hzz780/article/details/26611431 "pure JS Ajax readystate do not return 4,jquery $." Ajax implementation ERROR,STATUS200 and the data can be displayed is further improved and the problem is clear.

Problem, always return error, I modified the setcontenttype, and did not return to success as scheduled, began to find other reasons.

Run to see the $.ajax of jquery. Use documentation

When you debug with chrome, the data returned is in this form

<span style= "White-space:pre" >	</span>{' Error ': 0, ' name ': ' Huangzongzhe '}

And the standard JSON is going to be like this

<span style= "White-space:pre" >	</span>{"error": 0, "name": "Huangzongzhe"}
To use double quotes instead of single quotes, anything that is wrong will cause $.ajax to throw an error.

Sure enough, in Java, all of the ' convert to ', $.ajax return to the success we want to say Rtnjson.replace ("'", "\"), and then output JSON, of course, directly into the stringbuffer inside the time with "\ "Just fine."
OK, there is a problem, we can read more documents. It's still amazing.

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.