ajax 封装
2019-10-17 本文已影响0人
一爷之秋
export request = function(url, method, success, fail) {
let ajax = null;
if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
} else {
ajax = new ActiveXObject('Microsoft.XMLHTTP');
}
ajax.onreadystatechange = function() {
if (ajax.readyState === 4 && ajax.status === 200) {
success && success(ajax.responseText);
} else {
fail && fail();
}
};
ajax.open(method, url, true);
ajax.send();
}