function sendAjax(url){
return new Promise((resolve,reject)=>{
const xhr = new XMLHttpRequest()
xhr.open('GET',url)
xhr.send()
xhr.onreadystatechange=function(){
if(xhr.readyState ==4){
if(xhr.status>=200&&xhr.status<300){
resolve(xhr.response)
}else {
reject()
}
}
}
})
}
原生ajax封装
于 2022-02-08 21:28:04 首次发布