Skip to content Skip to sidebar Skip to footer

Wait For The End Of Two Asynchrounous Functions Before Firing A Third (jquery Deferred ?)

I'm trying to understand jQuery's Deferred, but inspite of samples, I can't achieve what I want to do. So, I'd like to call 2 functions asynchrounously, and, when BOTH are ended, c

Solution 1:

function1 and function2 must return promise objects for this to work. For example,

function function1 () {
    return $.ajax({...});
}

now you can use $.when

$.when(function1(),function2()).done(function3);

Edit: or:

$.when(function1(),function2()).done(function(){
    function3("test");
});

Post a Comment for "Wait For The End Of Two Asynchrounous Functions Before Firing A Third (jquery Deferred ?)"