I encountered an interview question today, that is, if there are two asynchronous ajax operations on the page, because the execution order of the two asynchronous operations is not sure, how to execute a new operation after both operations are executed? What's the best approach?
I answered method one at that time: nest two ajaxes and perform new operations in the return function of the second ajax. Interviewer's reply: This method is too lame.
So I thought about the second answer: monitor local variables through the timer setTimeout, and ensure that the two asynchronous operations are completed before performing a new operation. Interviewer's reply: The performance of this method is not good. Can you think of a simple and more reasonable method?
Thoughts failed at the time
So I put this question up to find what is the best way? Welcome to discuss and give advice
If it were simpler, I would choose to use a js framework like vue or angular that can bind data in two directions to do this. Various callbacks are too troublesome