The AJAX approach to jquery:
$.ajax ({
URL: '/comm/test1.php ',
Type: ' POST ',//get
Async:true,//or FALSE, whether asynchronous
data:{
Name: ' Yang ', age:25
},
timeout:5000,//Time-out
DataType: ' json ',//Return data format: Json/xml/html/script/jsonp/text
Beforesend:function (XHR) {
Console.log (XHR)
Console.log (' before sending ')
},
Success:function (DATA,TEXTSTATUS,JQXHR) {
Console.log (data)
Console.log (Textstatus)
Console.log (JQXHR)
},
Error:function (xhr,textstatus) {
Console.log (' ERROR ')
Console.log (XHR)
Console.log (Textstatus)
},
Complete:function () {
Console.log (' End ')
}
})
Native Ajax methods:
$ (' #send '). Click (function () {
5 Stages of the request, corresponding to the value of the readystate
0: Uninitialized, the Send method is not called;
1: Sending the request, the Send method has been called;
2: After the request is sent, the Send method is executed;
3: The response content is being parsed;
4: Response content parsing completed;
var data = ' Name=yang ';
var xhr = new XMLHttpRequest (); Create an Ajax object
Xhr.onreadystatechange = function (event) {//Listening to Ajax objects
if (xhr.readystate = = 4) {//4 means parsing is complete
if (Xhr.status = = 200) {//200 for normal return
Console.log (XHR)
}
}
};
Xhr.open (' POST ', ' url ', true); Establish connection, parameter one: Send method, two: Request address, Third: asynchronous, true Async
Xhr.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded '); Dispensable
Xhr.send (data); Send
});
The Ajax and native Ajax methods of jquery