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();//发送请求

posted on 2022-04-11 07:38  TANTT  阅读(42)  评论(0)    收藏  举报