jquery uses Ajax methods to get JSON data not to perform success and its solution _jquery

Source: Internet
Author: User

1.jquery get JSON data via Ajax method do not perform success callback

Problem Description: jquery obtains JSON data without executing success callback method via Ajax method

Problem reason: The JSON format has problems or does not conform to standard notation, causing the error callback method to always be executed

Solution: Make the JSON format must conform to the following 3 standard formulations:

1) Key name: enclosed in double quotes;

2) String: enclosed in double quotes;

3 numbers, Boolean values do not need to use double quotes around;

Note: must be double bracket!

2.jQuery Ajax using JSON data type always skips success execution Error statement

Execution function

Error:function (XMLHttpRequest, Textstatus, Errorthrown) {
//This error function is useful when debugging, and if parsing is incorrect, the error box
alert is ejected ( Xmlhttprequest.responsetext); 
alert (xmlhttprequest.status);
alert (xmlhttprequest.readystate);
alert (textstatus); Parser error;
}

I know the wrong message;

The pop-up box shows:

<! DOCTYPE HTML PUBLIC "-//w3c//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> and <?xml version=" 1.0 "encoding=" gb2312 "?>

These two words, though not clear why, after I deleted, succeeded in executing success

3.$.ajax () The URL in the Cross-domain, always does not perform success, old entry error

1) I add Servletactioncontext.getresponse (). SetHeader ("Access-control-allow-origin", "*");

To solve the cross-domain problem, we went into success.

2) DataType: "JSON",

Remove to see can enter success not.

DataType is the type of information expected to return from the server.

Reason: The returned data type must conform to the defined data type. That is, if you are defining a JSON-type DataType, the returned data must be JSON, flat and otherwise executing the program block in the error.

(1) It is also necessary to pay special attention to whether the returned JSON data is in strict JSON format.

(2) There should also be serious concern that when the background returns a list of data (the data in the list is in JSON format), there is no dirty data that is not strictly JSON format.

The above is a small set of jquery introduced to you by the Ajax method to get JSON data does not perform success reasons and solutions, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone, Here also thank you very much for the cloud Habitat Community website support!

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.