In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the relevant knowledge of "what is the default submission method of ajax". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what is the default submission method of ajax" can help you solve the problem.
Ajax defaults to asynchronous commit; AJAX is divided into synchronous "false" and asynchronous "true" according to the async value, while the default async value is true (asynchronous commit). The advantage of this is that it can not only improve the user experience through local refresh, but also save resources and reduce the pressure on the database.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
The default submission method of ajax is asynchronous submission, which has the advantage of improving the user experience through local refresh, while saving resources and reducing the pressure on the database.
AJAX is divided into synchronous (async = false) and asynchronous (async = true) according to the value of async.
$.ajax ({type: "post", url: "path", cache:false, async:false, dataType: ($.browser.msie)? "text": "xml", success: function (xmlobj) {function1 () {};}}); function2 () {}
By default, async is true (asynchronous commit).
The way to change it to synchronization is to change the default value of async to false, which is usually true or not written. If you change it to false, you will lose the function of ajax itself.
What is a synchronous request: (false)
A synchronous request means that after the current request is made, the browser can do nothing, and the subsequent code will not be executed until the request is completed, which is equivalent to queuing that the previous person finishes his own transaction and the next person can proceed. In other words, when the JS code is loaded into the current AJAX, all the code in the page will stop loading, and the page will be in a suspended state. When the AJAX is finished, it will continue to run other code pages to release the suspended state (that is, when the ajax returns data, the following function2 will be executed).
What is an asynchronous request: (true)
Asynchronous request when the request is made, the browser can continue to do anything, and Ajax sending the request will not affect the loading of the page and the operation of the user, which is equivalent to going their own way on two lines without affecting each other.
The general default value is true, which is asynchronous. Asynchronous requests can not affect the experience of the user at all, no matter the time of the request is long or short, the user is concentrating on other contents of the page and will not have the feeling of waiting.
What's the difference between synchronous and asynchronous:
Async: in asynchronous mode, there may be code to execute after we use AJAX to send the request. At this time, the server may not respond to our request for a variety of reasons, but because we have adopted asynchronous execution, the remaining code in all functions that contain the AJAX request code will continue to execute. If we leave the result of the request to another JS function, it is as if two threads are executing at the same time.
Synchronization: in synchronous mode, when we use AJAX to send the request, there is still code to be executed, and we also hand over the server response to another JS function to deal with, but the code execution situation is: when the server does not respond or the JS function that handles the response result has not completed the return, the remaining code of the function containing the request code cannot be executed. Just like a single thread, the request goes into a blocking state after it is made, and the rest of the code will not continue until the contact blocks.
Look at the following code:
Var flag=true;var index=0;$.ajax ({url: ", success: function (data) {flag=false;}}); while (flag) {index++;} alert (index)
In the end, the program entered an endless cycle.
Look at the following code:
Var flag=true;$.ajax ({url: ", success: function (data) {flag=false;}}); alert (flag)
The end result is true
Js is single-threaded, and the result is not returned because it takes a certain amount of time to execute the ajax request, or even a network failure. At this time, if the request is executed synchronously, you must wait until the ajax returns the result before the next code can be executed. If the ajax request takes 1 minute, the program has to wait 1 minute. If it is executed asynchronously, while waiting for the return of the server side, the foreground will continue to execute the script behind the ajax block, and the success will not be executed until the server side returns the normal result. At this time, two threads are executed, the thread after the ajax block sends the request and the script behind the ajax block.
Var flag=true;var index=0;$.ajax ({url: ", async:false, success: function (data) {flag=false;}}); while (flag) {index++;} alert (index)
The final result is 0
This is the end of the content about "what is the default submission method of ajax". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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: 295
*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.