When to use asynchronous or synchronous AJAX

Usually best to use an asynchronous call

 You Rui core courses through java study notes, we can see that a lot of the code of professional knowledge, learning to share your reference.

AJAX Asynchronous JavaScript and representatives of XML, is a technology to allow asynchronous update page, which means when the page is only a small part of the data when the change occurs, the browser does not need to reload the entire page. AJAX updates only the information passed to the server or from the server.

Standard Web applications synchronize the interaction between the visitor and the Web server. This means one thing after another happened. The server does not perform multiple tasks. If you click the button, the message will be sent to the server, and returns a response. Before the response and updates the page, you can not interact with any other page elements.

Obviously, this delay may have a negative impact on Web visitor experience - and therefore is AJAX.

What is AJAX?

AJAX is not a programming language, but a combination of technology and client-side scripting (ie a script that runs on the user's browser) Web server communication. In addition, its name somewhat misleading: although AJAX applications can send data using XML, but may only use plain text or JSON text. Typically, however, it uses the XMLHttpRequest object browser requests data from the server, and display the data using JavaScript.

AJAX: synchronous or asynchronous

Synchronous and asynchronous AJAX can access the server:

  • Synchronous, the script, the script stops and waits for the server to send complex answer, and then continue.
  • · Asynchronously, the script makes the page to continue processing, handling replies and arrival and arrival.

Sync your request and reload the page similar, but only download the requested information, rather than the entire page. Therefore, the simultaneous use of AJAX faster than not using AJAX - but it still needs your visitors wait for the download to complete before continuing any interaction with the page. People know that sometimes they have to wait for a page to load, but most people are not accustomed to continued high after a delay on the site.

Asynchronous processing your request to avoid the delay will be retrieved from the server, because your visitors can continue to interact with the web page; the requested information will be processed in the background, in response to the update page when the page arrives. In addition, even if the response is delayed (for example, in the case of very large data), site visitors may not be aware of it, because they are occupied elsewhere on the page.

Therefore, the preferred method is to use asynchronous AJAX calls as possible. This is the default setting in AJAX.

Why use synchronous AJAX?

If the asynchronous call provides such an improved user experience, so why AJAX provides a completely synchronized method call?

Although in most cases the asynchronous call is the best choice, but in rare cases, it does not allow visitors to interact continue until the completion of specific server-side process makes sense and pages.

In many cases, it is best not to use AJAX, but just reloading the entire page. The AJAX sync option applies to a small number of cases, in which case you can not use an asynchronous call, but do not need to reload the entire page. For example, you may need to address some order is important transaction. Consider a case, in this case, the page after the user clicks needed something to return the confirmation page. This task requires synchronization requests.

 

> Like this article can be a point of praise, welcome to leave comments, remember to focus on me, constantly updated technology dry every day, workplace fun, massive interview data, etc.
 > If you are interested in java technology can also exchange study, learn together progress. 
> Do not use the "no time" to hide his ideological laziness! Young, hard fight, give an account of their own future

Article wrote here, welcome to improve communication. Finally, we offer a complete set of java architecture Mind Mapping recently sorted out, knowledge sharing control reference point for everyone to learn. More JVM, Mysql, Tomcat, Spring Boot, Spring Cloud, Zookeeper, Kafka, RabbitMQ, RockerMQ, Redis, ELK, Git Java and other dry goods

 

Guess you like

Origin www.cnblogs.com/youruike1/p/12367352.html