[轉]多個ajax請求時控制執行順序或全部執行後的操作
阿新 • • 發佈:2018-07-18
on() .when ati ack login tps als fun lan
alert("done");
}).fail(function(){
alert("fail");
}); dataType: "json",
type: "post",
success: function (paraResponse) {
}
});
本文轉自:https://blog.csdn.net/fsdad/article/details/71514822
一、當確保執行順序時:
1、 請求加async: false,,這樣所有的ajax就會同步執行,請求順序就是代碼順序
2、$.when($.ajax(
{async: false,
url : url1
}
), $.ajax(
{async: false,
url : url2
}
)).done(function(){
alert("done");
}).fail(function(){
alert("fail");
});
二、確保所有異步的ajax請求完畢時
1、 ajax6 = $.ajax(
{
url: "/Home2/SelectyjLoginuser",
dataType: "json",
type: "post",
success: function (paraResponse) {
}
});
ajax7 = $.ajax(
{
url: "/Home2/Selectyjzh",
type: "post",
success: function (paraResponse) {
}
});
//確保(ajax6, ajax7兩個請求完畢時執行
$.when(ajax6, ajax7).done(function () {
//所做操作
});
}
2、上述的第二種同樣也可以用
[轉]多個ajax請求時控制執行順序或全部執行後的操作