Can I make multiples jquery ajax requests with the $.when method, without knowing the number of arguments?
This is my code:
var ajax_loaded = new Array();
$('.chart input[name^="qtd"]').each(function()
{
ajax_loaded.push(function(){$.ajax({
url : www + 'chart/add',
type : 'POST',
data : {
qtde: $(this).val(),
idProd: $(this).prev().val()
}
})});
});
$.when(ajax_loaded ).done(function(){
alert('Done');
});
Yes – use
Function.applyto call$.when()with your array of unknown length:NB: note that you need to push the result of
$.ajaxinto the array, not a function. Pushing a closure won’t work.