window.onload = function(){
  document.getElementById('btn').onclick = function(){
    var req = new XMLHttpRequest();
    req.open('get', 'demo.php');   //建立服务器连接 get 或 post请求
    req.onreadystatechange = function(){   //ajax请求状态变化
      if(req.readyState == 4 && req.statu == 200){   //200状态表示返回成功
        var str = req.responseText;
        alert(str)
      }
    }
      req.send();//对服务器发送请求
   }
}

相关文章:

  • 2021-08-11
  • 2021-11-13
  • 2021-10-09
  • 2021-10-08
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2021-07-15
  • 2022-02-20
  • 2022-12-23
相关资源
相似解决方案