Synchronization:After submission, wait for the server to respond. After receiving the data returned by the server, run the following command:Code;
Asynchronous:In contrast to the above, after the submission, continue to execute the following code, and continue listening in the background, after the server respondsProgramAsynchronous operations do not have to wait for the server to continue to do other tasks on the client.
Sometimes when we write JavaScript, the following code uses the data returned through Ajax,
If it is asynchronous at this time, the problem will occur:
Because it is asynchronous, when the following code is executed, the returned data may not have been obtained,
Solution:
① The following code first checks whether the data has been obtained before using the returned data. If not, setinterval () is used, check whether the data is obtained at intervals.
② Encapsulate the following code into a method, and then put this method into the Ajax asynchronous return method above.