0
我不能jQuery的等價這段代碼的發現插件:jQuery插件順序Ajax請求
function get() {
var list = ['obj1', 'obj2', 'obj3', 'obj4', 'obj5'],
requests = [];
for(i = 0; i < list.length; i++) {
requests.push($.ajaxQueue({
type: "POST",
url: "/echo/html/",
data: {html: list[i]},
success: function(data) {
$("div").append("Call " + data + "<br>");
}
}));
}
return requests;
}
$(document).on("click", "button", function(){
$.when.apply(null, get()).then(function(){
$.each(arguments, function(key, val){
$("div").append(
"Status: " + val[2].status + ", " +
"responseText: " + val[2].responseText + "<br>"
);
});
});
});
jsfiddle.net
- 一切的一切方法
jsfiddle.net
後 - 一個接一個方法
什麼此代碼在做:
- 允許配置ajax請求作爲一個模板湖
- 允許在每個ajax請求執行成功函數後一致。
- 允許在所有請求完成時執行函數,並提供對jqXHR對象數組的訪問。
我怎麼看這個插件:
$.ajaxMulti({
type: "POST",
url: arrayOfUrls,
data: {name: ""}
// other ajax options
})
.oneDone(function(data){
// manipulate with data (sequence observed)
})
.allDone(function(objects){
// execute when all requests done
});
幫助鏈接:
- https://stackoverflow.com/a/14352218/712308
- https://stackoverflow.com/a/3035268/712308
- https://stackoverflow.com/a/16208232/712308