Jqueryajax call failure example _ jquery

Source: Internet
Author: User
Jquery fails to be called in the process of using ajax. You may have encountered it. In this article, we have a good example. I hope to help you. Below is a complete function:

The Code is as follows:


Function ReLoadPromotion (){
Var A = parseFloat ($ ("# pNormalTotal" ).html () + parseFloat ($ ("# pBarginTotal" ).html ());
JQuery. ajax (
{
Url: "/ajax/OrderRedemption. aspx? Vf = getlist ",
Type: "POST ",
DataType: "json ",
Data: {amount: },
Success: function (json ){
$ ("# FittingProductList tr. tableItem"). remove ();
Var data = json. list;
$. Each (data, function (I, n ){
Var id = n. pid;
Var row ="";
Row + ="";
Row + =""+ N. pname +"";
Row + ="Full "+ n. amount +"";
Row + =""+ N. price +"";
Row + ="";
$ ("# FittingProductList"). append (row );
});
$ ("# PromotionArea"). slideDown ();
CalculateOrder ();
},
Error: function (xml ){

// Alert (arguments [1]);
Var json = eval ("(" + xml. responseText + ")");
$ ("# PromotionArea"). slideUp ();
}
});
}


In many cases, you may find that you directly jump to error during debugging, and then directly jump over. the success segment is not executed. in fact, all the statements here are correct. The key to the problem is the return value. if an error occurs in the returned value, the success segment is not executed. errors in returned values may occur in the following situations:

1. format error. this is relatively simple. It is common to include a comma, for example, {"success": true, "list": [{},{},]}. (add a comma at the end) normally, this is not the case. In case of errors, the comma is not processed at the end of the for statement.

2. type Error: This type of error is the most difficult to find. If you are unsure, it is the best to use characters. for example, "success": true is acceptable, "code": 0, or yes. if it is "code": a123, a conversion error occurs. this is true: "code": "a123"

Errors are ignored during jquery debugging, so sometimes they get crazy. A simple method is to write the error statement and add alert. errors will be captured.

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.