在 jQuery 3(参见问题)中,它看起来像是改变progress
了$.when
行为。当我的每个延期都得到解决时,我希望得到一个进度通知:
var urls = [
'https://httpbin.org/delay/2',
'https://httpbin.org/delay/1'
];
console.log('started');
var deferreds = $.map(urls, function(url) {
var d = $.Deferred();
$.ajax({
url: url,
type: 'GET'
})
.always(function(){
console.log('done %o', url)
d.notify();
d.resolve.apply(this, arguments);
});
return d.promise();
});
$.when.apply(jQuery, deferreds).progress(function(){
// Does not call
console.log('progress?');
}).done(function(){
console.log('all done');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
代码也在codepen上。电流输出:
“开始”
“完成https://httpbin.org/delay/1 ”
“完成https://httpbin.org/delay/2 ”
“全部完成”
我希望progress?
在每个完成的请求后看到一个输出。
当前的 jQuery API 有没有很好的方法来实现这种行为?