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();//发送请求
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。