I have three functions. I want to do something when function two (after one) and three are all done. What should I do?
function one(){
$.ajax({
url:'url'
}).done(function(res){
two();
})
}
function two(){
$.ajax({
url:'url'
})
}
function three(){
$.ajax({
url:'url'
})
}

Return the $.ajax promises from each function then you can use $.when()
function one() {
return $.ajax({
url: 'url'
}).then(two);
}
function two() {
// return request promise
return $.ajax({
url: 'url'
})
}
function three() {
// return request promise
return $.ajax({
url: 'url'
})
}
$.when(one(),three()).then(function(){
//all three requests completed here
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With