我使用AJAX請求successives,我需要做一個回調時,所有的successives請求完成雙Ajax請求的響應
function doAjaxRequest(data, id) {
// Get payment Token
return $.ajax({
type: "POST",
url: 'exemple1.php',
data: data
success: function(msg){
$.ajax({
type: "POST",
url: 'exemple2.php',
data: msg,
success: function(msgr) {
document.getElementById(id).value=msgr;
},
error:function (xhr, status, error) {
//Do something
}
});
},
error:function (xhr, status, error) {
//Do something
}
});
}
$.when(
doAjaxRequest(data, "input-1"),
doAjaxRequest(otherData, "input-2")
).done(function(a1, a2){
//Need do something when both second ajax requests (example2.php) are finished
}
有了這個代碼,該完成的功能是之前我的電話給「exemple2電話。 PHP「成功。
我該如何等待?
感謝您的回答!
糾正我,如果我錯了,但IE不支持它,對吧? –
https://api.jquery.com/category/deferred-object/在IE上支持,具有相同的邏輯。 謝謝! – Bouffe