const pro=new Promise((res,req)=>{
let xml=new XMLHttpRequest();
xml.open('GET','http://baidu.com');
xml.send()
xml.onreadystatechange=()=>{
if(xml.readyState==4){
if(xml.status==200){
res(xml.response)
}
req(console.error(error))
}
}
})
pro.then(function(value){
console.log(value);
},function(reason){
console.warn("出错了!!!");
}).catch(function(){
console.log('出错了,请注意');
})
可以实现把Ajax拿到的内容在全局中使用