I have structure of my programm like this
if(some condition){
$.ajax(...);
}
if(some condition){
$.ajax(...);
}
doSomething();
How I can wait responce of async $.ajax functions before doSomething()? Is it "true way" to use async: false ?
I have structure of my programm like this
if(some condition){
$.ajax(...);
}
if(some condition){
$.ajax(...);
}
doSomething();
How I can wait responce of async $.ajax functions before doSomething()? Is it "true way" to use async: false ?
You could push these requests in an array:
var requests = [];
if(some condition){
requests.push($.ajax(...));
}
if(some condition){
requests.push($.ajax(...));
}
$.when.apply($, requests ).done(doSomething);