Jquery1.8 uses ajax to analyze the problems and solutions of WeChat calls. jquery1.8ajax

Source: Internet
Author: User

Jquery1.8 uses ajax to analyze problems and solutions for calling. jquery1.8ajax

Background: I am working on a project recently to develop a function that uses asp.net DEVELOPMENT AND jquery1.8.0.

In the event triggered by clicking the button, ajax is called to interact with the server, and the callback function follows an error.

Cause analysis:The first thing I think of is that there is a problem with the returned data type, because the json format is very strict in jquery 1.4 and later versions, and must comply with {"target": true, "message ": "success. JSON. stringify () function is used to analyze the response object. The result is correct and the cause is excluded.

Since ajax uses error, I began to analyze the parameters of the error function, including XMLHttpRequest, textStatus, and errorThrown. I found that XMLHttpRequest. status is equal to 0 and XMLHttpRequest. readyState is equal to 0, indicating that the XMLHttpRequest object in the form is not initialized. Next I will study how to initialize the XMLHttpRequest object.

Solution:

var xmlHttpRequest;$(function(){if(window.XMLHttpRequest){xmlHttpRequest=new XMLHttpRequest();}else{xmlHttpRequest=new ActiveXObject("Microsoft.XMLHTTP");}xmlHttpRequest.open("GET","AjaxServlet",true);});

In this way, the problem described above can be solved. Note that normal Ajax access on the PC side will not be affected, because browsers in the PC have built-in XMLHttpRequest objects, but in the middle, this phenomenon occurs, you may need to build and initialize them manually.

Ps: Android browser and IE6 browser ajax request abort error handling

A click event is bound to the page element to trigger ajax requests. In Android browsers and IE6, requests are often interrupted and the Error Type "abort" is returned ", everything works in other browsers.

When I use Fiddler2 and httpWatch in IE6 to monitor requests, "aborted" is often displayed. It's a weekend ,.....

Don't talk nonsense ....

Solution: Add onclick = 'Return false; 'to the tag ;'

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.