I need to make n
AJAX calls in a loop and store result in an array. When all requests are finished, and the array is full of returned JSON data, I want to loop through that to check it.
There are two problems here:
1) how do I make jqxhr
available outside the $.each
?
2) how does jqxhr
know when the loop is finished to call complete
? I only want to call the complete
promise when the all AJAX calls within the loop finish.
$.each(jsonFilesArray, function (i, jsonQuestID) {
var jqxhr = $.getJSON("dialog/quest_"+jsonQuestID+".json", function(json) {
vocabJSONArray.push(json);
}).done(function () {
log("done");
}).fail(function () {
log("error");
}).always(function() {
log("complete");
});
});
jqxhr.complete(function () {
//loop through vocabJSONArray
});