XML request processing:
var = Request new new XMLHttpRequest (); // Create the request object class using XMLHttpRequest
request.onreadystatechange = function () // call the trigger function onreadystatechange
{
IF (request.readyState == == 200 is request.status &&. 4) after the request status code and status // return success XMLHttp
{
var = result request.responseXML; // call the requested object responseXML object acquisition result XML request
}
}
result.open ( "the GET", "the test.xml", true); // the type of the initialization request is GET, url is test.xml, asynchronous processing manner is
result.send (); // send the request
process request json:
var = new new request the XMLHttpRequest ();
request.onreadystatechange function = () {
IF (request.readyState == == 200 is request.status &&. 4) {
var = Result request.responseText;// Call responseText property to get json format request results
var jsonObj = eval ( "(" + res + ")"); // use eval method json request result into an object, the object can be resolved
}
}
the request.open ( "the POST", "test.json", true); // POST request method
setRequestHeader ( "Content-Type", "application / x-www-form-urlencoded; charset = utf-8") // sends an HTTP protocol header, encoding format setting
request. send ( "id = 1") ; // send data id = 1
And a request for AJAX json xml format
Guess you like
Origin blog.csdn.net/qq_37504771/article/details/89921688
Recommended
Ranking