1. Get Data using XMLHttpRequest: Open () and send () open (Method,url,anync)
Method:get/post. URL: Address Anync: Submit method, True indicates asynchronous/false represents synchronous Send (String)
If the submission is get,string=null if the submission is post,string= information that needs to be sent
Add
//Set HTTP header information, must be placed between open and send.
Request.setrequestheader (");
//
//
2.XMLHttpREquset Get a response
ResponseText |
gets the response data returned as a string |
Responsexml |
Gets the response data returned in the form of XML |
Stastus and StatusText |
Returns an HTTP status code as a number and text |
Getallresponseheader |
Get all response headers |
getResponseHeader |
The value of a field in a query response |
Readystatus Property
4 | The
request is complete and the response is ready |
0 |
The request has not been initialized and open has not yet been invoked |
1 |
The server has established a link and open has been called |
2 |
Request received, receive header information |
3 |
In request processing, a response principal is received |
Sample
Sends a request and processes--js--
//commits with a GET method, executes the asynchronous commit to the server.php
function () {
var request=new xmlhttprequest ();
Request.open ("Get", "server.php", true);
Request.send ();
Verify
request.onreadystatechange=function () {
if (request.readystatus===4&) by Onreadystatuschange event &request.status===200)
{
//If the request succeeds, this part of the Operation
}else{
alert ("Error occurred" +request.readystatus);
}
}
}
//Add, modify--js--//Submit with Post, execute asynchronous commit to server.php function () {var request=new xmlhttprequest ();
Request.open ("POST", "server.php", true); Suppose you get data from the form var data= "name=" +document.getelementbyid (' name '). Value + "&age=" +document.getelementbyid (' age '). V
Alue;
Set HTTP header information Request.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Post mode submission information request.send (data); Verify Request.onreadystatechange=function () {if (request.readystatus===4&&request) by Onreadystatuschange event
. status===200) {//If the request succeeds, this part of the Operation}else{alert ("Error occurred" +request.readystatus); }
}
}