XMLHttpRequest 用于在后台与服务器交换数据。这意味着可以在不重新加载整个网页的情况下,对网页的某部分进行更新。

创建 XMLHttpRequest对象

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

 }  

 

 如需将请求发送到服务器,我们使用 XMLHttpRequest 对象的 open() 和 send() 方法,具体参考:http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_send.asp

xmlhttp.open("GET","test1.txt",true); xmlhttp.send();
 

 

AJAX - 服务器响应:

如需获得来自服务器的响应,请使用 XMLHttpRequest 对象的 responseText 或 responseXML 属性。具体参考:
 http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_response.asp

属性 描述
responseText 获得字符串形式的响应数据。
responseXML 获得 XML 形式的响应数据。
 

 

AJAX - onreadystatechange 事件

具体参考:http://www.w3school.com.cn/ajax/ajax_xmlhttprequest_onreadystatechange.asp 

 

相关文章:

  • 2022-01-05
  • 2021-10-16
  • 2022-12-23
  • 2021-11-10
  • 2022-01-05
  • 2021-09-12
  • 2022-03-03
  • 2022-12-23
猜你喜欢
  • 2021-10-05
  • 2021-08-27
  • 2021-09-16
  • 2021-10-28
  • 2021-10-10
相关资源
相似解决方案