Unable to perform success resolution after $.ajax returned JSON-formatted data

Source: Internet
Author: User

The recent project, using AJAX technology in the project, encountered a strange problem: "TheJSON-formatted data returned by $.ajax cannot be executed success", as the code reads:

1 $.ajax ({ 
 2). 
 3 dataType: ' JSON ', 
 4 ... 
 5 Success:function (jsondata) { 
 6//Do not perform success 
 7}, 
 8 error:function (Error) { 
 9//Always execute this error 
10} 
11});

Why, why is this so? Checking the returned JSON string, I think the format of the JSON string should be OK, so I looked it up on the internet and found that there were really people who had the same problem as me, to find out why " because I specified datatype: ' JSON ', The JSON format requirements are very strict , at first my JSON format is written: "{result:{\" success\ ": \" true\ ", \" meg\ ": \" Success\ "}", but this can not be written, it must be changed to write: " {\ "success\": True,\ "mesg\": \ "Success\"} ", if it is bool type, then do not use quotes, the other keys/values need to be quoted." after jquery 1.4, the JSON format has been tightened, meaning that the {"key" of this format must be required: "Value ', ' key ': ' value '}; like the original {key: value, key: value} and {' key ': ' Value ', ' key ': ' Value '} This is wrong, not standard, So jquery returns the error. previously did not notice such a problem, this encounter, but also found a solution, in this record.

Related Article

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.