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/02 Report--
This article mainly explains "what are the requests of 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 are the requests of AJAX.
The AJAX request can be summarized as a fixed piece of code:
Script type= "text/javascript" >
Var xmlhttp; / / XMLHttpRequest object
Try {/ / code for IE7+, Firefox, Chrome, Opera, Safari
Xmlhttp=new XMLHttpRequest ()
} catch (e) {/ / code for IE6, IE5
Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP")
}
What are the requests from AJAX
Xmlhttp.onreadystatechange=function () {/ / event handler function
If (xmlhttp.readyState==4 & & xmlhttp.status==200) {
/ / write your code here. You can use responseText to receive the returned data.
}
}
Xmlhttp.open (POST/GET,url,true); / / Select the sending method and determine the url
Xmlhttp.send (data); / / data sent in POST mode, left blank in GET mode
/ script >
GET or POST?
GET is simpler and faster than POST, and can be used in most cases.
However, use the POST request in the following cases:
Cannot use cache files (update files or databases on the server)
Send a large amount of data to the server (POST has no data limit)
POST is more stable and reliable than GET when sending user input that contains unknown characters.
Whether to request asynchronously
For the open () method:
Open (method,url,async)
Async is true or false.
When async=true, JavaScript does not need to wait for the response from the server, but can execute other scripts while waiting for the response from the server, and then process the returned data when the response is completed. Therefore, the AJAX request is separate from the execution of other scripts and does not affect each other.
When async=false, JavaScript will wait until the server response is complete before continuing to execute other scripts, and if the server is busy or slow, JavaScript will wait and may hang or stop. This approach only applies to small and simple requests.
AJAX refers to asynchronous JavaScript and XML (Asynchronous JavaScript and XML). For web developers, sending asynchronous requests is a huge step forward, greatly reducing server overhead and increasing the speed of client script execution. AJAX focuses on "asynchronism". If async=false, AJAX goes to the meaning. Therefore, if there are no special requirements, it is generally async=true that can not only give full play to the role of AJAX, but also will not encounter inexplicable mistakes.
Thank you for your reading, the above is the content of "what are the requests of AJAX". After the study of this article, I believe you have a deeper understanding of what requests AJAX has, 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.