function
ajax(method
, url
, callback
, data
, flag
) {
var xhr
= null
;
if(window
.XMLHttpRequest
) {
xhr
= new XMLHttpRequest();
}else {
xhr
= new ActiveXObject('Microsoft.XMLHttp')
}
xhr
.onreadystatechange
= function() {
if(xhr
.readyState
== 4) {
if(xhr
.status
== 200) {
callback(xhr
.responseText
);
}else {
console
.log('error');
}
}
}
method
= method
.toUpperCase();
if(method
== 'GET') {
var date
= new Date(),
timer
= date
.getTime();
xhr
.open(method
, url
+ '?' + data
+ '&timer=' + timer
, flag
);
xhr
.send();
}else if(method
== 'POST') {
xhr
.open(method
, url
, flag
);
xhr
.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhr
.send(data
);
}
}
转载请注明原文地址: https://yun.8miu.com/read-57397.html