使用原生JS写出一个AJAX请求
2019-06-17 本文已影响0人
December1224
let request = new XMLHttpRequest()
request.open('get','xxx')
request.send()
request.onreadystatechange = ()=>{
if(request.readyState === 4){
if(request.status >= 200 && request.status < 300){
console.log('说明请求成功')
let string = request.responseText
let object = window.JSON.parse(string)
}
}else if(request.status >= 400){
console.log('说明请求失败')
}