想象一个场景,我们想要在 'foo' 和 'bar' 的并发请求成功完成后做一些事情,或者如果其中一个或两个都失败则报告错误:
$.when($.getJSON('foo'), $.getJSON('bar'))
.then(function(foo, bar) {
console.log( 'I fire if BOTH requests are successful!' );
})
.fail(function() {
console.log( 'I fire if one or more requests failed.' );
});
我如何确定 1) 对“foo”的请求是否失败,或者 2) 对“bar”的请求是否失败,或者 3) 如果两者都失败了?