<script type="text/javascript">
  var xmlHttp = null;
  function create() {
    //创建ajax技术核心对象XmlHttpRequest
    if (window.ActiveXObject)
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    else
      xmlHttp = new XMLHttpRequest();
  }
  function sum() {
    create(); //创建ajax核心对象,准备一次异步请求
    xmlHttp.open("GET", "Application1.aspx"); //与服务器建立连接
    xmlHttp.onreadystatechange = b;//指定回调函数
    xmlHttp.send();//发送请求
  }
  function b() {
    if (xmlHttp.readystate == 1)
      alert("连接建立好了");
    else if (xmlHttp.readystate == 2)
      alert("已发送请求");
    else if (xmlHttp.readystate == 3) {
      alert("正在执行中");
    }
    else if (xmlHttp.readystate == 4) {
      if (xmlHttp.status == 200)
        alert("结果为:" + xmlHttp.responseText);
      else if (xmlHttp.status == 404)
        alert("网址有问题");
      else if (xmlHttp.status == 500)
        alert("服务器正在更新");
  }
}
</script>

posted on 2014-07-03 16:09  村夫哥哥  阅读(1091)  评论(0编辑  收藏  举报