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