function ajax(url) {
return new Promise (function(resolve, reject){
let xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onload = function () {
if(xhr.readyState == 4){//4代表解析完成
if(xhr.status === 200){
resolve(req.responseText);
}else{
reject(new Error(req.statusText));
}
}
}
xhr.send();
})
}
ajax("http://localhost:3000/test").then(res=>{
console.log(res.data);
}).catch(err=>{
})
11-03
09-01
308
08-18