He I have a problem I need to send multiple AJAX calls to the same URL but with different data. I need to send it in chunks and wait until all requests are done before my _.each function.
i did a simple chunk function that slice my array and slip it to groups.
my code:
---- js ----
batch = [0,1,2,3,4,5,....] // big array
var xhr = chunk(batch, 20);
for (i=0; i < xhr.length ; i++ ) {
//loop number of time of xhr.length
ajax.call("/", "POST", {batch: xhr[i]}).done(function(resp){
arrayResp.push(resp);
});
}
/// after all ajax calls and arrayResp is done
exectue
_.each(arrayResp, function (element) {
//do somting
});
----- /js -----
i need to get in the end a full array that holds all my resp data
I can't do $.when() because I can't name the function And I didn't figure out how to use the $.Deferred() in this function Can you help me?
Thanks!