Home  >  Q&A  >  body text

js best how to perform a new operation after two AJax async operations

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

世界只因有你世界只因有你2663 days ago1624

reply all(11)I'll reply

  • 漂亮男人

    漂亮男人2017-07-05 10:56:02

    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

    reply
    0
  • Cancelreply