In my JavaScript code, I am facing the following situation:
call_A(success_A)
call_B(success_B)
function call_A(success){
// make ajax request
success(result)
}
function call_B(success){
//make ajax request
success(result)
}
function success_A(){
//set data to be used by success_B
}
function success_B(){
..do some stuff
}
I need to execute both call_A
and call_B
consecutively in order to perform AJAX calls efficiently.
I am unable to modify the function headers of call_A
and call_B
, so I have to specify the success callback function when calling these functions.
My objective is to ensure that regardless of which AJAX call completes first, success_A
is invoked before success_B
, since the latter relies on data from the former.
What would be the most effective approach to accomplish this?