var req = new XMLHttpRequest();
req.onreadystatechange = function(){
if(req.readyState === 4){
if(req.status ===200){
console.log(req.responseText)
}else{
console.log('错误码:'+req.status)
}else{
console.log('进行到哪一步了'+req.readyState)
}
}
req.readyState返回值详解:
0 - (未初始化)还没有调用send()方法
1 - (载入)已调用send()方法,正在发送请求
2 - (载入完成)send()方法执行完成,已经接收到全部响应内容
3- (交互)正在解析响应内容
4 - (完成)响应内容解析完成,可以在客户端调用了
req.status错误码详解:
https://blog.csdn.net/qq_41818857/article/details/108709543