Straightforward explanation Ajax synchronous, asynchronous

  • Asynchronous AJAX:

  • The main thread: . "Hello, AJAX thread you please help me send a HTTP request, and I put the request addresses and parameters gave you."

  • AJAX thread: "Okay, I'll go to the main thread of hair, but it may take a little time, you can go to busy with something else.."

  • The main thread: : "Thank you, you get a response back to tell me ah."

  • (Then, the main thread to do other things to go after a meal time, it received a notification response arrives.)

  • Synchronous AJAX:

  • The main thread: . "Hello, AJAX thread you please help me send a HTTP request, and I put the request addresses and parameters gave you."

  • AJAX thread: "......"

  • The main thread: : "Hey, AJAX thread, how do you not speak?"

  • AJAX thread: "......"

  • The main thread: : "Hey Hey Hey!!"

  • AJAX thread: "......"

  • (After a stick of incense)

  • The main thread: : "! Hey Please say something!"

  • AJAX thread: "the main thread, sorry, I can not talk at work when your request has been made over, to get the response data, and to you.."

It is because JavaScript is single-threaded, non-blocking and asynchronous easy to implement, so in JavaScript or time-consuming operation for the operation time of uncertainty, the use of asynchronous became the inevitable choice.

Guess you like

Origin www.cnblogs.com/1115changhao/p/11792917.html