wucf2004的博客

asp.net和ajax
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

js xmlhttprequest

Posted on 2008-08-01 14:34  wucf2004  阅读(1031)  评论(0编辑  收藏  举报
<script type="text/javascript">
 var xmlHttp;
 function createXMLHttpRequest() {
     if (window.ActiveXObject) {
         xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest) {
         xmlHttp = new XMLHttpRequest();
     }
 }
 
 function startRequest() {
     createXMLHttpRequest();
     xmlHttp.onreadystatechange = handleStateChange;
     xmlHttp.open("GET", "simpleResponse.xml", true);
     xmlHttp.send(null);
 }
 
 function handleStateChange() {
     if(xmlHttp.readyState == 4) {
         if(xmlHttp.status == 200) {
             alert("The server replied with: " + xmlHttp.responseText);
         }
     }
}
 </script>