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.