Let’s say I have the following javascript:
(function($) {
$.getJSON(url, function(data) {
$.each(data.rows, function(index, row) {
$.getJSON(url2, function(data2) {
//Do something with data2, like adding it to an element on the page.
//When all rows have been processed, by this function, I want to
//call a function.
}
}
}
})(jQuery)
I would like to be notified when all the inner $.getJSON has returned.
In my real code, I will use a callback function that I would like to be called when all requests are done.
You could probably use
jQuery.when()for this, like:Edit: just realised that
whenwon’t taken an array as argument, so I changed the code use.applyinstead.