Ajax interface and background interaction

Source: Internet
Author: User

//define a way for the public to deal with Ajax    functionHandelajax (url,method,parm,callback) {$.ajax ({url:url, Type:method, Datatyp E:' JSON ', Data:pram, success:function(data) {callback (data); }, Error:function(ERR) {alert (ERR); }        })    }//Implementing QueriesHandelajax ('/user/search ', ' post ', {name: ' Wes '},function(data) {//Post-Success ActionsConsole.log (' Data: ', data); });
View Code

One of the reasons why Ajax jumps into the error function:

Any errors will jump to the error function;

Give an example of the cause of the error:

Problem with 1.URL path

There is no Chinese in the path

2. Problems with the passed parameters

The parameter must be an AJAX-supported encoding format, such as: With Json.parm (), json.stringify (), etc.

3.data cannot be empty

Pass a "{}" even if you do not pass the value

4.dataType

Background incoming datatype and foreground write inconsistencies

5.async Request Synchronous Asynchronous problem

Async Default Request method is true (asynchronous request), if you want an AJAX request to complete before requesting another Ajax, you need to set Async to false;

For example, you use a POST request to pass a value to another page background, but the page once loaded your Ajax has been executed, the value receive is completed in the background, the request is not the data, so you can consider the AJAX request to synchronize to try.

Reference to an online blog about the reasons why Ajax jumps into the error function

Ajax interface and background interaction

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.