I can pass in multiple ajax calls into a when like this:
var dnldAy = [];
for (i=0, iMax=urlsToLoad.length; i < iMax; i++) {
dnldAy.push( $.ajax({
url: urlsToLoad[i],
dataType: "json"
}) );
}
$.when.apply($, dnldAy).done( function( doneCb ) {
console.log( doneCb );
}
When when
runs it is only getting the first doneCb from the array of ajax requests. I understand I could add more parameters to the done function to get the other callbacks, but this is not extensible. (I am going to have an unknown number of ajax calls in my when
, so I cannot know how many parameters I will need in the done function ahead of time).
What is the right way to handle this design problem?