In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the AJAX request mode and synchronous asynchronous what is the difference, the article is very detailed, has a certain reference value, interested friends must read it!
Request method is divided into GET and POST:
GET
The most common HTTP request, the general 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. )
The copy code is as follows:
/ / synchronous transmission mode
Function RequestByGet (nProducttemp,nCountrytemp)
{
Var xmlhttp
If (window.XMLHttpRequest)
{
/ / isIE = false
Xmlhttp = new XMLHttpRequest ()
}
Else if (window.ActiveXObject)
{
/ / isIE = true
Xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP")
}
/ / Web page location.
Var URL= "http://www.baidu.com/;
Xmlhttp.open ("GET", URL, false)
/ / xmlhttp.SetRequestHeader ("Content-Type", "text/html; charset=Shift_JIS")
Xmlhttp.send (null)
Var result = xmlhttp.status
/ / OK
If (result==200)
{
Document.getElementById ("div_RightBarBody") [xss_clean] = xmlhttp.responseText
}
Xmlhttp = null
}
/ / Asynchronous transfer mode
Var xmlhttp
Function RequestByGet (nProducttemp,nCountrytemp)
{
If (window.XMLHttpRequest)
{
/ / isIE = false
Xmlhttp = new XMLHttpRequest ()
}
Else if (window.ActiveXObject)
{
/ / isIE = true
Xmlhttp = new ActiveXObject ("Microsoft.XMLHTTP")
}
/ / Web page location.
Var URL= "http://www.baidu.com/";
Xmlhttp.open ("GET", URL, true)
Xmlhttp.onreadystatechange = handleResponse
/ / xmlhttp.SetRequestHeader ("Content-Type", "text/html; charset=UTF-8")
Xmlhttp.send (null)
}
Function handleResponse ()
{
If (xmlhttp.readyState = = 4 & & xmlhttp.status==200)
{
Document.getElementById ("div_RightBarBody") [xss_clean] = xmlhttp.responseText
Xmlhttp = null
}
}
The above is all the content of this article entitled "what is the difference between request mode and synchronous asynchrony in AJAX". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
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.