Ajax was a new technology that was born in the February 2005 but is now hot. This new technology can greatly improve the user experience of the site.
What is Ajax
Ajax is an English abbreviation for asynchronous JavaScript and XML (asynchronous JavaScript and XML).
The core idea of Ajax is to send an asynchronous request using a XMLHttpRequest object. Ajax is not a new language or technology, it is actually a number of technologies are grouped together in a certain way, to play their role in a common collaboration.
The advantages of Ajax
1. Reduce the burden on the server. The principle of Ajax is "data on demand".
2. No need to refresh the page, reduce the user's psychological and actual waiting time.
3. Bring a better user experience.
4. Some of the work of the server can be transferred to the client, the use of the client idle capacity to deal with, reduce server burden, make full use of broadband resources, save space and broadband rental costs.
5. External data can be invoked.
6. Based on standardized and widely supported technologies, there is no need to download plug-ins or small programs.
7. Further promote page rendering and data separation.
Two. Introduction of XMLHttpRequest Objects
One of the biggest features of Ajax is the fact that you can transfer or read or write data to the server without refreshing the page (also known as no Refresh Update page), which is mainly thanks to the XMLHTTP component XMLHttpRequest object.
XMLHttpRequest Property
Properties of the XMLHttpRequest object
Property |
Describe |
onReadyStateChange |
This event handler is triggered when each state changes, and typically a JavaScript function is invoked |
ReadyState |
Status of the request |
ResponseText |
The response of the server, expressed as a string |
Responsexml |
The response of the server, expressed as XML, that can be resolved to a DOM object |
Status |
HTTP status of the server |
StatusText |
Corresponding text for HTTP status |
This event handler is triggered when each state changes, and typically a JavaScript function is invoked
XMLHttpRequest method
Some common methods of XMLHttpRequest objects
Method |
Describe |
Abort () |
Stop current request |
getAllResponseHeaders () |
Returns all the corresponding headers of an HTTP request as a key/value pair |
getResponseHeader ("header") |
Returns the string value of the specified header |
Open ("Method", "url") |
Establish a call to the server. The method parameter can be get,post or put, and the URL parameter can be a relative URL or an absolute URL. This approach also includes 3 optional parameters |
Send (content) |
Send a request to the server |
setRequestHeader ("header", "value") |
Sets the specified header to the supplied value and must first call the open () method before any header is set |