【发布时间】:2013-02-20 20:48:34
【问题描述】:
当我有可变数量的 ajax 请求时,如何使用延迟调用它们?
我的猜测:
//qty_of_gets = 3;
function getHTML(productID, qty_of_gets){
var dfd = $.Deferred(),
i = 0,
c = 0;
//this is where there could be some magic to
//do multiple ajax posts
//obviously I'm out of my depth here...
while (i <= qty_of_gets){
dfd.pipe(function(){
$.get("queries/html/" + product_id + i + ".php");
});
i++
}
dfd.done(function(){
while (c <= qty_of_gets){
$('myDiv').append(c);
c++;
}
});
}
【问题讨论】:
-
如果你只是将 ajax 请求自动返回的延迟对象粘贴到一个数组中,然后用一点 apply() 将数组放入 $.when 中,你就会到达那里!跨度>
标签: javascript jquery jquery-deferred