【发布时间】:2017-05-19 13:06:29
【问题描述】:
在 jQuery 3(参见 issue)中,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 有没有很好的方法来实现这种行为?
【问题讨论】:
标签: jquery jquery-deferred jquery-3