Synchronous and asynchronous and synchronous and asynchronous differences between async attribute values in Ajax

Source: Internet
Author: User

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.



The Ajax method in jquery has a property of async for controlling synchronization and Asynchrony, which by default is true, that is, AJAX requests are asynchronous requests by default, and sometimes Ajax synchronization is used in projects. This synchronization means that when the JS code is loaded into the current AJAX will be the page all the code to stop loading, the page appears suspended animation state, when this Ajax execution will continue to run other code page suspended animation state lifted. Asynchronous is the same as when the Ajax code is running, as other code can run.

The async attribute in Ajax, which controls how data is requested, is true by default, which is the default way to request data asynchronously.

One, async value is true (async)

When the Ajax sends the request, in the process of waiting for the server side to return, the foreground will continue executing the script behind the AJAX block until the server side returns the correct result to execute the success, that is, two threads are executing. Ajax blocks make a request after a thread and a script behind the Ajax block (another thread)

For example

?$.ajax ({type: "POST", url: "Venue.aspx?act=init", DataType: "HTML", success:function (Result) {//function1 (       ) F1 ();      F2 ();      } failure:function (Result) {; },} function2 ();

In the example above, when the Ajax block makes a request, he will stay function1 () and wait for the server side to return, but at the same time (during this wait), the foreground will execute function2 ().

Second, async value is False (synchronous)

When executing the current AJAX will stop the execution of the following JS code, until the completion of Ajax execution, to continue to execute the following JS code.

For example

?

Synchronous and asynchronous and synchronous and asynchronous differences between async attribute values in Ajax

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.