//创建一个ajax的对象
let xhr = new XMLHttpRequest();
//创建一个请求 (方式和路径)
xhr.open('get','http://localhost:4000')
//发送请求
xhr.send();
//处理服务器响应的信息
xhr.onreadystatechange=function(){
// xhr的完成状态 xhr的状态码
if(this.readyState===4&&this.status===200){//数据接收完毕
//获取响应信息
let data = this.responseText;
//转换成js对象
data= JSON.parse(data)
console.log(data)
}
}
浅尝ajax
于 2022-06-06 20:07:48 首次发布