In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain what Ajax means for you in detail. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
What is AJAX?
AJAX = Asynchronous JavaScript and XML (asynchronous JavaScript and XML).
AJAX is not a new programming language, but a new way to use existing standards.
AJAX is the art of exchanging data with a server and updating parts of a web page without reloading the entire page (AJAX is a technology for creating fast dynamic web pages).
By exchanging a small amount of data with the server in the background, AJAX can update web pages asynchronously. This means that some part of the page can be updated without reloading the entire page.
Traditional web pages (without AJAX) if you need to update the content, you must reload the entire web page.
XMLHttpRequest object
The core of Ajax is the JavaScript object XmlHttpRequest
Function createXHR () {var xhr = null;try {/ / Firefox, Opera. +, Safari,IE+xhr = new XMLHttpRequest ();} catch (e) {/ / Internet Explorer try {xhr = new ActiveXObject ("Msxml.XMLHTTP");} catch (e) {try {xhr = new ActiveXObject ("Microsoft.XMLHTTP");} catch (e) {xhr = null;}} return xhr;}
XMLHttpRequest object usage
There are two important methods for XMLHttpRequest objects: open and send
The first method to be called when using the XMLHttpRequest object is the open method, which is called by XMLHttpRequest.open ("get", "default.aspx", true). This code sends a get request for the default.aspx page. There are three points to note about this code:
1. URL is the path relative to the current page, or you can use an absolute path
two。 Calling the open method does not actually send the request, but initializes a request ready to be sent
3. Requests can only be sent to URL in the same domain that use the same protocol and port, otherwise an error will be reported for security reasons
To send the request to the server, you need to call the send method. The send method takes a parameter, which is the data to be sent by the request subject, and if you do not need to send the data, pass it to null. After calling the send method, the request is sent to the server, as follows
Xhr.send (null)
The request is sent to the server, and the server generates a response (Response) according to the request, which is returned to the XHR object. After receiving the response, the corresponding data will be populated into the properties of the XHR object, and four related attributes will be populated:
1. ResponseText: the text returned as the body of the response
2. ResponseXML: if the type of response content is "text/xml" or "application/xml", this property will save the XML document containing the corresponding data
3. Status: HTTP status of the response (200404500, etc.)
4. StatusText:HTTP status description
Onreadystatechange event
When the request is sent to the server, we need to perform some response-based tasks.
Whenever the readyState changes, the onreadystatechange event is triggered.
The readyState property stores the status information of the XMLHttpRequest.
Here are three important properties of the XMLHttpRequest object:
In the onreadystatechange event, we specify the task to be performed when the server responds that it is ready to be processed.
When readyState equals 4 and the status is 200, the response is ready:
Xmlhttp.onreadystatechange=function () {if (xmlhttp.readyState== & & xmlhttp.status==) {document.getElementById ("myDiv") [xss_clean] = xmlhttp.responseText;}}
We can call the abort method to cancel the asynchronous request before accepting the response: XMLHttpRequest. Abort ()
Note:
When using the send () method of the XMLHttpRequest object, if you are using a get request or a post request that does not need to send data, you need to use send (null)
If you want to send data, you need to use a post request, first using setRequestHeader () to add the HTTP header. Then specify the data you want to send in the send () method:
Xmlhttp.open ("POST", "ajax_test.asp", true); xmlhttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send ("fname=Bill&lname=Gates"); this is the end of the article on "what does Ajax mean?" I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.