原生ajax的实现步骤
1创建对象
2设置请求方式和请求地址
3发送请求
4监听状态变化
5返回数据
var xhr = new XMLHttpRequest()
xhr.onreadystatechange = function(){
if(xhr.readyState != 4)return;
if(xhr.status == 200 && xhr.readyState == 4){
console.log(xhr.responseText)
}else{
console.log("请求失败")
}
}
xhr.open("get","http://localhost:3030")
xhr.send()