In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What is the role of async in ajax? aiming at this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Async in ajax is used to set the script to be executed asynchronously or synchronously; the async attribute value defaults to true in asynchronous mode. After "$. Ajax" is executed, the script behind ajax will continue to be executed. When its property value is set to false, the synchronous request will lock the browser, and other user operations must wait for the request to be completed.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
What is the function of async in ajax
Async. The default is true, which is asynchronous, and after $. Ajax executes, it continues to execute the script behind ajax until the server returns data and triggers the success method in $. Ajax, which executes two threads. To set it to false, all requests are synchronous requests, and before a return value is returned, the synchronization request will lock the browser, and other user operations must wait for the request to complete.
Let's look at an example:
Var temp;$.ajax ({async: false,type: "POST", url: defaultPostData.url, dataType: 'json', success: function (data) {temp=data;}}); alert (temp)
This ajax request is a synchronous request and alert (temp) will not be executed until there is no return value.
If async is set to: true, the result of the ajax request will not be waited, and the statement that follows the ajax will be executed directly.
However, when setting the synchronization request above, some netizens once reported that after setting async to false, the original intention was to return the data and execute the script after $.Ajax. Unexpectedly, this place led to a splash screen under Firefox (Firefox 11.0) and a scroll bar to the bottom to trigger ajax. In the end, we can only comment out the async:false, that is, if async is ture, we have successfully solved the problem that the Firefox browser scroll bar is pulled down to the bottom to trigger the ajax to splash screen.
The answer to any question about the role of async in ajax is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.