ajax请求数据
作者:互联网
var xhr = new XMLHttpRequest();//实例化HTTP请求对象
// xhr.open('请求类型','文件在服务器中的位置',同步(false)异步(true))
//post方式要传参时,需要加请求头
//xhr.setRequestHeader('content-type','application/x-www-form-urlencoded');
xhr.onreadystatechange = function(){
console.log(xhr.readyState);//监听请求发送到哪儿个步骤
if (xhr.readyState == 4 && xhr.status == 200) {
// 200 请求成功
alert(xhr.responseText);//弹出相应内容
}
}
xhr.open("get","1.txt",true);//设置请求
xhr.send();//发送请求
标签:200,readyState,请求,true,open,xhr,ajax,数据 来源: https://www.cnblogs.com/TANM/p/16128457.html