I found the problem about Ajax Asynchronization today

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.