jquery Ajax Call Failed reason example introduction _jquery

Source: Internet
Author: User
Here's a finished function:
Copy Code code 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:A},
Success:function (JSON) {
$ ("#fittingProductList Tr.tableitem"). Remove ();
var data = json.list;
$.each (data, function (I, n) {
var id = n.pid;
var row = "<tr id=\" Trpromotin "+ ID +" \ "class=\" tableitem\ ">";
Row + = "<td><input id=\" Cbpromotionitem "+ ID +" \ "type=\" checkbox\ "value=\" "+ n.pid +" \ "Name=\" Promotionpro Duct\ "title=\" "+ N.price +" \ "Onclick=\" Calculateorder () \ "/></td>";
Row + + "<td><label for=\" Cbpromotionitem "+ ID +" \ ">" + n.pname + "</label></td>";
Row + + "<td> full" + N.amount + "</td>";
Row + + "<td>" + N.price + "</td>";
row = = "</tr>";
$ ("#fittingProductList"). append (row);
});
$ ("#promotionArea"). Slidedown ();
Calculateorder ();
},
Error:function (XML) {

Alert (arguments[1]);
var json = eval ("+ Xml.responsetext +"));
$ ("#promotionArea"). Slideup ();
}
});
}

A lot of times when you are debugging you will find that you jump directly to the error, and then jump straight past. The success segment was not executed. In fact, all the statements here are not a problem, the crux of the problem is the return value. If the return value fails, he does not perform the success segment.

1. The format is wrong. It's quite simple, it is more common to have a comma, such as: {"Success": True, "list": [{},{},]} (last more than one comma) normal does not have this, error prone when you use a For statement when the last did not deal with that comma.

2. Type error: This error is most difficult to find, it is best to use characters if you are not sure. For example: "Success": True is OK, "code": 0, also can. If it is "code": A123, there is a problem and there is a conversion error. To do this: "Code": "A123 "

Because it ignores errors during jquery debugging, it can be maddening sometimes. An easy way is to write an error statement, plus alert, where the error is captured.
Related Article

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.