The Ajax method of jquery is set on the return value type when no return value

Source: Internet
Author: User

2013-12-07 19:15:29|  Category: Web Front end | Tags:html | Report | Font size Subscription

$.ajax ({

Type: "Post",

URL: "index.php",

Data: "Id=" +uid,

DataType: "JSON",

Success:function () {

Alert (1);

},

Error:function () {

Alert (0);

}

});

In the Ajax method of jquery, after passing the parameters, the callback determines that there are two cases of success and error.

Sometimes, when the return value is not required, throw in the format of the template, set the dataType: "JSON", parameters;at this time, when the value of the Ajax is correct, 200 returned to the success of the error status of the special case.

You have not previously noticed the setup problem for the return value data type of the Ajax method. In the absence of callback parameters, it is generally not necessary to set the data type of the return value. If you set an error, you will usually be an error. This time, the direct cancellation DataType: "JSON",

Parameters can be.

The correct template for Ajax methods with no return value:

$.ajax ({

Type: "Post",

URL: "index.php",

Data: "Id=" +uid,

Success:function () {

Alert (1);

},

Error:function () {

Alert (0);

}

});

Again, if the callback parameter data format is not JSON, the same cannot be set dataType: "JSON" to avoid similar problems.

Transfer from http://wu110cheng.blog.163.com/blog/static/133349654201311771529542/

The Ajax method of jquery is set on the return value type when no return value

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.