jquery gets JSON data through AJAX methods without executing success

Source: Internet
Author: User

1.jquery fetching JSON data via Ajax method does not perform success callbacks

Problem Description: jquery gets JSON data through AJAX methods without executing the success callback method

Problem reason: JSON format is problematic or does not conform to standard notation, resulting in the error callback method being always executed

Solution: Make JSON format must conform to the following 3 standard notation:
1) Key name: Enclose in double quotation marks;
2) String: Enclose in double quotation marks;
3) numbers, Boolean values do not need to be enclosed in double quotes;

Note: It must be a double parenthesis!

2.jQuery Ajax using JSON data type always skips success execution Error statementExecute function error:function (XMLHttpRequest, Textstatus, Errorthrown) {//This error function is very useful when debugging, if parsing is incorrect, an error box will pop up
alert (Xmlhttprequest.responsetext);
alert (xmlhttprequest.status);
alert (xmlhttprequest.readystate);
alert (textstatus); Parser error;
}
The error message is clear; 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, although not clear why, I delete, after the successful implementation of success3.$.ajax () URLs in cross-domain, always do not execute success, old into error

1) I add Servletactioncontext.getresponse (). SetHeader ("Access-control-allow-origin", "*");
Solve the cross-domain problem and get into the success successfully

2) DataType: "JSON",
Remove See can enter success not.
DataType is the type of information that is expected to be returned by the server.

Cause: The data type that is returned must conform to the defined data type. That is, if the dataType you define is a JSON type, the returned data must be JSON, flat and otherwise the block of error will be executed.
(1) It is also necessary to pay special attention to whether the JSON data returned is a strict JSON format.
(2) It should also be a serious concern that when the back of a list data is returned (the data in the list is in JSON format), there is no dirty data that is not a strict JSON format.

jquery gets JSON data through AJAX methods without executing success

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.