I have an ajax request that grabs some data and then splits it up into an array. The array length is variable.
var ajax1 = $.ajax({
url: 'myurl.php',
type: "GET",
dataType: "jsonp",
success: function (data) {
//create an array
}
});
Once I have the array, I want to loop through it and in each iteration run another AJAX request. I put it inside a $.when to make sure the initial ajax request was complete:
$.when(ajax1).done(
function() {
for (i = 0; i < array.length; ++i) {
$.ajax({
url: 'anotherurl?=' + myarray[i],
type: "GET",
dataType: "jsonp",
success: function (data) {
//do stuff here
}
});
}
}
)
My question is, how can I get a message box to pop up when the for loop has completed all the AJAX requests? A simple alert('complete')
at the end of the loop won't work as the AJAX is done async.