我有以下代码:
$('#remove-commercial-products-modal').find('form').submit(function() {
var promises = [];
var $modal = $(this).closest('.modal');
$(this).find('input:checkbox:checked').each(function() {
promises.push(
$.ajax({
url: '/commercial/products/unclaim/' + $(this).val() + '/',
dataType: 'json',
timeout: 10000,
cache: false
}));
});
$.when.apply($, promises).done(function(result) {
$modal.modal('hide');
});
return false;
});
所以,当我的表单被提交时,我收集了选中复选框的值,并创建了一个 Promise 数组,每个 Promise 都是一个 $.ajax 调用。
我的调用被执行,我的.done
函数中的代码被执行。
但是,我认为这.done
是期待一些论点,每个承诺一个。但我不知道我提前有多少,我希望得到一系列结果(每个结果都是 $.ajax 调用的响应。)
有人知道我是否可以将我的回复分组吗?谢谢!