jquery1.8 version use Ajax to implement the problem analysis and solution of micro-letter invocation _ajax related

Source: Internet
Author: User
Tags error handling

First of all, let us say the background: Recently in a project, the development of a micro-letter function, the use of ASP.net development, jquery1.8.0 version.

Click on the button to trigger the event in the micro-letter, invoke Ajax to interact with the server side, the callback function is error.

The reason: The first thing I thought of was the data type that was returned was problematic because in the jquery version more than 1.4 The JSON format was very strict and needed to conform to the format of {"Target": true, "message": "Success"}. The response object is analyzed with json.stringify () function, and the result is consistent and the reason is excluded.

Since Ajax is taking the error, I began to analyze the parameters of the error function, respectively, XMLHttpRequest, Textstatus, Errorthrown. I found that xmlhttprequest.status equals 0,xmlhttprequest.readystate equals 0, stating that there are XMLHttpRequest objects in the form that are not initialized, and then begin to study how to initialize XMLHttpRequest objects.

Solution:

var XMLHttpRequest;
$ (function () {
if window. XMLHttpRequest) {
xmlhttprequest=new XMLHttpRequest ();
} else{
xmlhttprequest=new ActiveXObject ("Microsoft.XMLHTTP");
}
Xmlhttprequest.open ("Get", "Ajaxservlet", true);

This will solve the problem described above, note that PC-side access to general Ajax does not cause problems, because the browser in the PC has a built-in XMLHttpRequest object, and in the micro-letter, this phenomenon may need to manually build and initialize.

PS: Android micro-letter with browser and IE6 browser AJAX request abort error handling

A click event is bound to the page element to trigger an AJAX request, and in an Choweixin browser and IE6, the request is often interrupted, returning the error type "Abort", which is normal in all other browsers.

Using FIDDLER2 and HttpWatch monitoring requests in IE6, "aborted" is often present, and tossing a weekend, ...

Don't talk nonsense ....

Workaround: Add onclick= ' return false on the label

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.