The role of the async parameter in Ajax asynchronous requests in Jquery, jqueryasync

Source: Internet
Author: User

The role of the async parameter in Ajax asynchronous requests in Jquery, jqueryasync

I did not know the role of this parameter before. I went online to find a blog of my predecessors and recorded my blog here. I hope I can help more friends:

Test.html

<A href = "javascript: void (0)" onmouseover = "testAsync ()">

Asy. js

Function testAsync {
Var temp;
$. Ajax ({
Async: false,
Type: "GET ",
Url: 'tet. php ',
Complete: function (msg ){
Alert ('complete ');
},
Success: function (data ){
Alert ('success ');
Temp = data;
}
});
Alert (temp + 'end ');
}

Tet. php

<? Php

Echo "here is html code ";
Sleep (5 );

?>

Async: false (true by default );
As shown above: false indicates synchronization. The Ajax request in the testAsync () method will lock the entire browser,
Other operations can be performed only after the execution of tet. php is complete.

When async: true, ajax requests are asynchronous. However, there is a problem: ajax requests in testAsync () and subsequent operations are executed asynchronously, so when tet. php may have executed the operations following the ajax request,
For example, alert (temp + 'end ');
However, the temp data is assigned a value only after the ajax request success. The result is null in the output.

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.