In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the difference between synchronous and asynchronous ajax". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the difference between synchronous and asynchronous ajax".
Differences: 1, in synchronization, a thread has to wait for the last thread to finish execution before it can start execution, while in asynchronous, a thread is executing, the next thread does not have to wait for it to finish execution; 2, synchronization is a single-threaded operation, while async is a multi-threaded operation; 3, the efficiency of asynchrony is higher than synchronization.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Ajax Asynchronous request:
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. 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.
For example:
Ajax ({type: "POST", url: "Venue.aspx?act=init", dataType: "html", success:function (result) {/ / function1 () F1 (); f2 ();} failure:function (result) {alert ('Failed');},} function2 ()
Note: in the above code, when the ajax block makes a request, he will stop function1 () and wait for the server to return, but at the same time (in the process of waiting), the foreground will execute function2 ().
Ajax synchronization request:
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 is to say, 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 this ajax is finished, it will continue to run other code pages to release the suspended state (that is, when the ajax returns data, the subsequent function will be executed).
For example:
Ajax ({type: "POST", url: "Venue.aspx?act=init", dataType: "html", async: false, success:function (result) {/ / function1 () F1 (); f2 ();} failure:function (result) {alert ('Failed');},} function2 ()
Note: in the above code, when asyn is set to false, the request of ajax is synchronized, that is to say, after the ajax block sends the request, he will wait in the function1 () place and will not execute function2 () until the execution of the function1 () part is complete.
After reading the meaning of ajax synchronous and asynchronous requests, let's take a look at the difference between ajax synchronous and asynchronous requests.
The difference between ajax synchronous and asynchronous requests:
Synchronization means that a thread has to wait for the last thread to finish execution before it can start execution. Synchronization can be regarded as a single-threaded operation. As long as the client requests it, it is a thread blocking state before the server has no feedback.
Asynchronism is when a thread is executing, and the next thread does not have to wait for it to finish executing. Async must be multithreaded. When requested by the client, other threads can be executed and executed in an orderly manner when the thread is stored in his queue.
Asynchrony is more efficient than synchronization. If data is shared between threads, synchronization must be used!
In asynchronous mode:
When we have finished sending the request using AJAX, there may be code to execute. 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.
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 at this time is: when the server does not respond or the JS function that handles the response result has not finished processing 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.
Thank you for your reading, the above is the content of "what is the difference between ajax synchronous and asynchronous". After the study of this article, I believe you have a deeper understanding of the difference between ajax synchronous and asynchronous, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.