jquery - How to manage multiple ajax request/responses with a for loop and an array -
i trying make ajax request using loop , array in jquery mobile.
i trying to:
- send requests.
- store responses.
- after ajax completed, perform action.
here's have far doesn't work (that's why i'm here).
var req1 = []; var req2 = []; var size = //some number passed here//; //create size number of unique ajax json requests (i = 0; < size; i++) { requesta[i] = // request json datatype //; requestb[i] = $.ajax(requesta[i]); }; (j = 0; j < size; j++) { requestb[j].done (function (response) { if (response[j].results.length > 0) ( requestb[j] = response[j].results; } }); $(document).ajaxstop (function() { // after ajax done // });
try lock array when in callback.
something this
var isloked = false; // ... if (response[j].results.length > 0 && !islocked) ( islocked = true; requestb[j] = response[j].results; islocked = false; }
p.s. why dont want make request , assign callback @ same loop?
Comments
Post a Comment