Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between synchronous and asynchronous in Ajax

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

What is the difference between synchronous and asynchronous in Ajax? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

The request method is divided into GET and POST: GET is the most common HTTP request, and the ordinary web browsing page is GET. The parameter request in GET mode follows URL directly, starting with a question mark. (obtained with _ window.location.search in JS). Parameters can be encoded in encodeURIComponent, using:

Var EnParam = encodeURIComponent (param)

URL only supports a length of about 2K, that is, 2048 characters; when using GET for AJAX requests, the page will be cached so that the page is incorrect. The general method is to add the random parameter value; ajax.send (null).

POST

Used to submit data to the server.

You need to first take out the value in the form form and convert it to a string, concatenate it with the & symbol, (like passing parameters in GET); submit the amount of data 2GB; use ajax.setRequestHeader ('Content-Type',' application/x-www-form-urlencoded') to process the submitted string; ajax.send (strings), which represents what needs to be submitted in the form, such as a string like a=1&b=2.

Synchronous and asynchronous:

In the ajax.open method, the third parameter is set to be synchronous or asynchronous. Js class libraries such as prototype generally default to asynchronous, that is, set to true. First, in the case of synchronization, js will wait for the request to return and obtain the status. No onreadystatechange event handler is required. Asynchronism, on the other hand, requires onreadystatechange event handling, with a value of 4 to properly handle the following.

(note: the ajax in this article represents the XMLHTTP request object. )

After reading the above, have you mastered the difference between synchronous and asynchronous in Ajax? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report