Hi I'm pretty new to javascript and I have some questions regarding how .done() works with the .getJSON() function. Here is an example:
array1 = [];
loaded = false;
var req = $.getJSON("url", function(json) {
$.each(json, function(i, item) {
array1.push(item.name);
});
});
req.done(function(){
loaded = true;
func(array1);
});
Does the .done() function wait until the code in the callback function passed as a parameter is executed first, or is there a chance that the .done() function will fire and finish before the callback function. For an example, is there a chance that .done() will execute before the array has been filled up with all the data?
In the given example, is there any utility to doing things like this? Besides the ability to call .done() later than the success callback function?
If I want to call func(array1) as soon as the array is filled up with all the data retrieved, is it better to do it in the callback function or in .done()?