1.get Request
function ()
{
//Request time from Server
//1. To create an asynchronous object (small browser)
var xhr = new XMLHttpRequest ();
2. Set parameters, true to use asynchronous mode
Xhr.open ("Get", "Gettime.ashx?name= Mr Jing", true);
3. Let get requests do not get cached data from the browser
xhr.setrequestheader ("if-modified-since", "0");
3. Set callback function
Xhr.onreadystatechange = function ()
{
//3.1 when the response message is fully received and the response status code is 200
if ( Xhr.readystate = = 4 && xhr.status =
{
//3.2 get corresponding report stylistic content
var res = xhr.responsetext;
Alert (res);
}
;
4. Send asynchronous request
xhr.send (null);
}
2.post Request
function ()
{
//Request time from Server
//1. To create an asynchronous object (small browser)
var xhr = new XMLHttpRequest ();
2. Set parameter
xhr.open ("Post", "Gettime.ashx", true);
3. Set the encoding format of the request report style (set to the form default encoding format)
xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
4. Set callback function
Xhr.onreadystatechange = function ()
{
//3.1 when the response message is fully received and the response status code is 200
if ( Xhr.readystate = = 4 && xhr.status =
{
//3.2 get corresponding report stylistic content
var res = xhr.responsetext;
Alert (res);
}
;
5. Send asynchronous Request "Name=mr Jing"
//5.1 Format: Direct stitching string key=value&key1=value2
xhr.send ("Name=mr jing &age=18");
The above in-depth understanding of the Ajax get and POST request is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.