I am trying to achieve run a few functions which have ajax calls inside, In sequence. I am not able to do this asynchronously since they both start at the same time.
This is my code :
function engine_start() {
a1();
a2();
}
a1() {
$.ajax(
url: // some code and url
}).then(function(data) {
if (some_condition()) {
console.log("finished a1. success");
}
});
};
a2() {
$.ajax(
url: // some code and url
}).then(function(data) {
if (some_condition()) {
console.log("finished a2. success");
}
});
};
I want a2()
to execute only after a1()
is successful, which in my case is at finished a1. success
. Note some_condition()
also contains internal ajax requests so I need to take care of that too.
So My ideal run would be something like this :
1) engine_start()
2) a1 starts executing.
3) a1 finishes
4) a2 starts executing.
5) a2 finishes