Ajax 起步

Ajax 起步
Ajax学习 一
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
 if(window.ActiveXObject){            //判断是否是IE
  xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
 }else if(window.XMLHttpRequest){
  xmlHttp = new XMLHttpRequest();
 }
}
function startRequest(){
 createXMLHttpRequest();         //得到XmlHttp对像
 xmlHttp.onreadystatechange = handleStateChange;     //当请求状态改变时调用
 xmlHttp.open("GET","simpleResponse.xml",true);    //True表请求上本质是否异步
 xmlHttp.send(null);      //向服务器发送请求
}
function handleStateChange(){
 if(xmlHttp.readyState == 4){      // 4、数据接收完毕,此时可以通过通过responseBody和responseText获取完整的回应数据
  if(xmlHttp.status == 200){         //请求成功返回
   alert("The server replied with: " + xmlHttp.responseText);
  }
 }
}
</script>

你可能感兴趣的:(Ajax 起步)