I have to execute a callback function after all the asynchronous functions finishes execution.
For that I have created an array, containing asynchronous functions:
var funcs = [];
var requests = [];
In which I have pushed some ajax functions.
This is my solution which is not working:
for(i = 0; i < functions.length; i++){
var f = functions[i](); //calling each ajax functions
requests.push(f);
}
$.when.apply(null, requests).done(function(){
console.log("Hello");
});
Now functions are executing asynchronously, but the callback functions gets called before the functions execution finishes.
One of the example of ajax function I pushed :
functions.push(function () {
return $.ajax({
url: "some url",
success: function(){
console.log("Finished execution");
}
});