In Ajax, there are two ways to execute the synchronization (async = False) and asynchronous (async = True) according to the value of async, and asynchronous execution is recommended in the tutorials of the consortium;
Here's how synchronization differs from Asynchrony:
Asynchronous: In asynchronous mode, when we use Ajax to send out the request, there may be code that needs to be executed. This is a time when the server has not responded to our request for a variety of reasons, but the rest of the code in the function containing the AJAX request code will continue to execute because we are executing asynchronously. If we are handing the request results to another JS function, then this is like two threads executing at the same time.
Sync: In synchronous mode, when we use Ajax to send the request, followed by the code needs to be executed, we also put the server response to another JS function to deal with, but at this time the code execution is: in the server does not respond or processing response results of the JS function has not been processed to complete return, The remaining code for the function that contains the request code cannot be executed. Just like a single thread, the request is sent into a blocking state, knowing that the remaining code will not continue until the contact is blocked.
How do I choose between synchronous or asynchronous mode? To answer this question, we can answer the following questions that may arise:
After we send the AJAX request, we also need to continue processing the server's response, if we use the asynchronous request mode and do not leave the processing of the result to another JS function for processing. This can happen when the response to an asynchronous request has not yet been reached, and the function has finished executing the return statement, which results in an empty string.