AJAX之创建 XMLHttpRequest对象

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");

 }  

 

AJAX - 向服务器发送请求:

 如需将请求发送到服务器,我们使用 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 

 

posted on 2012-07-10 10:22  lee0oo0  阅读(331)  评论(0编辑  收藏  举报