Special and usage scenarios for AJAX synchronization and Asynchrony

Source: Internet
Author: User

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.

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.