Ajax Synchronous vs. asynchronous

Source: Internet
Author: User

1. How Ajax Works

  

2. Synchronization

The XMLHttpRequest object is used to exchange data with the server.

The async parameter of the open () method must be set to True if the XMLHttpRequest object is to be used with AJAX:

Xmlhttp.open ("GET","ajax_test.html",true);

Instead of waiting for a response from the server, Ajax,javascript does:

  • Execute additional scripts while waiting for the server to respond
  • Handle responses when they are ready

3. Asynchronous

To use Async=false, change the third parameter in the open () method to False:

Xmlhttp.open (" Get","test1.txt",false);

We do not recommend the use of Async=false, but for some small requests it is also possible.

Keep in mind that JavaScript waits until the server responds in readiness to continue. If the server is busy or slow, the application hangs or stops.

Ajax Synchronous vs. asynchronous

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.