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.