1. What is Ajax
Ajax, "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML), refers to a web development technique that creates interactive Web applications.
Ajax:asynchronous Javascript and XML, asynchronous JS and XML.
In 2002,Google introduced the "Google Suggest" effect in the search engine, naming the technology used as "AJAX", in order to avoid "a pale" in the browser. affect the browsing experience.
The principle of implementation: While the client browses the content of the Web page, the server provides the latest content, the local update in the page- no submission without refreshing the content of the Local update technology .
Ajax applications involve the technology: HTML, CSS, JS, DOM, XML, HTTP protocol, etc.-Pure front-end technology, need to interact with the Web server.
2. The browser initiates the HTTP request in two ways:
(1) Synchronization request: Address bar, form submission, hyperlink jump, JS jump
(2) Asynchronous request: Using the XHR object
3. Steps to initiate an HTTP request using XHR
1 Creating a Xhr Object
var xhr = new XMLHttpRequest ();
2 Monitoring the status change events of XHR
Xhr.onreadystatechange = function () {
if (xhr.readystate===4) {//Response message receive complete
if (xhr.status===200) {//response completed and successful
}else{//Response completed but there is a problem
}}}
3 Connecting to the server
Xhr.open (' GET ', ' x.php ', true);
4 Sending a request message
Xhr.send (Null/' k=v&k=v ');
4.XHR Object member properties:
- readystate:0 Ready State , automatically changing with request -response
- Response: ""
- ResponseText: "" Response message body , readyState becomes 3 only has value
- Responsetype: ""
- Responseurl: ""
- Responsexml:null response message body , readyState changes to 3 to have value
- status:0 Response Status Code ,readyState changed to 2 to have value
- StatusText: "" Reason ,readyState changed to 2 to have value
- timeout:0
- Done:4 ReadyState One of the desirable values, the response message receives completion
- Headers_received:2 ReadyState One of the desirable values to begin receiving the response message header
- Loading:3 ReadyState One of the desirable values to begin loading the response message body
- Opened:1 ReadyState One of the desirable values,XHR has opened a connection to the server
- unsent:0 ReadyState One of the desirable values, the request message has not been sent
5.XHR Object member Methods:
- getAllResponseHeaders:getallresponseheaders ()
- getResponseHeader:getresponseheader () read response header
- setRequestHeader:setrequestheader () set request Header
- Open: Opened() opens a connection to the server
- Send: Sent() sends a request message
The problem with Ajax