- 创建一个XMLHttpRequest类型的对象,相当于打开一个浏览器
var xhr = new XMLHttpRequest();
- 打开一个与网址之间的连接——相当于在地址栏输入访问地址
xhr.open('get','http://localhost:3000');
- 通过链接发送一次请求——相当于回车或者点击访问发送请求
xhr.send();
- 指定xhr状态变化事件处理函数——相当于处理网页已呈现后的操作
xhr .onreadystatechange = function(data) {
if(this.readyState===4){
document.write("hello world");
}
}