Ajax synchronous with asynchronous pits

Source: Internet
Author: User
Before the work of a requirement, need to dynamically add a set of drop-down menu and binding a plug-in for this menu, it is obvious to get the data with Ajax, which in itself is true, pit on the pit when I used the synchronization request, when the server side to return the data correctly when the next method, the logic itself is not a problem. So when I finished, I found that the page load speed and its slow, I deleted some redundant and HTTP requests, still do not solve the problem, and then I suddenly think of the Ajax synchronous and asynchronous problems, after the change to asynchronous page data loading is much faster, hoping to use the correct synchronous and asynchronous. In jquery Ajax method Async is used to control synchronization and Asynchrony, when the async value is true is an asynchronous request, and when the async value is Fase, it is a synchronous request. The async attribute in Ajax, which controls how data is requested, is true by default, which is the default way to request data asynchronously. 1, Async value is true (async) when Ajax sends a request, in the process of waiting for the server side to return, the foreground will continue executing the code behind the AJAX block until the server side returns the correct result before executing the success, that is, two threads are executed at this time , the AJAX block makes a request after a thread and a script behind the Ajax block (another thread) 2, the async value is False (synchronous) Ajax makes a request, and no more code is executed while the server side returns, pausing in the current request, Until the server side correctly returns the data, the success callback method in Ajax is executed before the rest of the code is executed until the callback execution is complete.

Ajax synchronous with asynchronous pits

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.