好的,jQuery Ajax返回Deferred
Object,这可以帮助您实现这一目标。
这是操作方法:
var args = ['arg1','arg2','arg3','arg4','arg5','arg6'];deferredPost(0, 5);function deferredPost(index, max){ var delay = Math.random()*3; if (index<max){ return $.post('/echo/html/', {html:('Response to '+args[index]), delay:delay}, function(data){ $('#response').append(data+'<br>'); }).then(function(){ deferredPost(index+1, max); }); } else { return $.post('/echo/html/', {html:('Response to '+args[index]), delay:delay}, function(data){ $('#response').append(data+'<br>'); }); }}演示
在这里,我用 那么 函数。
我还建议多读一些有关延迟对象的知识,它们可以解决几个常见问题。



