Ajax has all been known, is to achieve asynchronous communication, improve user experience, and will be a lot of old knowledge (Xml,dom,javascript,html,jquery,css ... ) to re-integrate a new knowledge framework. And, the XMLHttpRequest object is one of the heavy. This blog highlights the use of this object. Of course, according to the classic five-step study, in the future in practice there are more and better ideas, will come out to share!
First, you need to understand the properties and methods of this object first:
Property |
Description |
| readystate |
xmlhttprequest object: 0: uninitialized. Object created, open Span lang= "en-US" >1:open method successfully invoked, but Sendf method not called; 2 :send The method has been called, the data has not yet begun to be accepted; 3: Accepting data. http The response header information has been accepted but not yet received; 4: Complete, that is, the response data accepts completion. |
onReadyStateChange |
An event trigger that requests a state change (readyState changes to invoke the JavaScript function registered on this property ). |
ResponseText |
The text content of the server response |
Responsexml |
DOM object corresponding to the XML content of the server response |
Status |
The HTTP status code returned by the server . "Success," said 404, " not Found", " server Internal error" and so on. |
StatusText |
The server returns text information for the status. |
Method |
Description |
Open (String method,string url,boolean asynch, String username,string Password) |
Specify and server-side interaction httpurl address, that is, other request information; method: http request method, generally using "GET", "POST". url: Represents the address of the requested server; asynch: Indicates whether an async method is used, truefalse behind two can not be specified, usernamepassword< The span lang= "ZH-CN", respectively, represents the user name and password, providing http The user name and password required by the authentication mechanism. |
Send (content) |
The request is made to the server, and if it is asynchronous, the method returns immediately. Content can be specified as null to not send data, and its contents can be DOM objects, input streams, or strings. |
setRequestHeader (String header,string Value) |
Sets the value of the header of the specified header in the HTTP request to values . This method is called after the Open method and is typically used in post mode. |
getAllResponseHeaders () |
Returns all the response header information that contains Http, with the corresponding header including Content-length,date,uri, and so on. The return value is a string that contains all the header information, where each key name and key value is separated by a colon, and each set of keys is separated by a CR and LF(carriage return plus line break)! |
getResponseHeader (String header) |
Returns the value of the header corresponding to the key name specified in the HTTP response header |
Abort () |
Stops the current HTTP request. The corresponding XMLHttpRequest object is reset to the uninitialized state. |
XMLHttpRequest also has "browser cache problem", "Chinese garbled problem", "cross-domain access problem" and so on, because they have not encountered these things, so here first understand, later encountered serious study!
ajax--Core XMLHttpRequest Objects