本示例主要演示如何操作XMLHttpRequest..... 

XMLHttpRequest 简介

要真正实现这种绚丽的奇迹,必须非常熟悉一个 JavaScript 对象,即 XMLHttpRequest。这个小小的对象实际上已经在几种浏览器中存在一段时间了,它是本专栏今后几个月中要介绍的 Web 2.0、Ajax 和大部分其他内容的核心。为了让您快速地大体了解它,下面给出将要用于该对象的很少的几个 方法和属性。

open():建立到服务器的新请求。 

send():向服务器发送请求。 

abort():退出当前请求。 

readyState:提供当前 HTML 的就绪状态。 

responseText:服务器返回的请求响应文本。 

客户端HTML代码:

复制代码 代码如下:

<script language="javascript" type="text/javascript">    var xmlHttp = false;    try {      xmlHttp = new XMLHttpRequest();    } catch (trymicrosoft) {      try {        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");      } catch (othermicrosoft) {        try {          xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        } catch (failed) {          xmlHttp = false;        }        }    }    if (!xmlHttp)      alert("Error initializing XMLHttpRequest!");    function getCustomerInfo() {      var phone = document.getElementById("qq").value;      var url = "demo2.asp?qq=" + escape(phone);      xmlHttp.open("GET", url, true);      xmlHttp.onreadystatechange = updatePage;      xmlHttp.send(null);    }    function updatePage() {      if (xmlHttp.readyState == 4) {    if (xmlHttp.status == 200) {    var response = xmlHttp.responseText.split("|");    document.getElementById("message").innerHTML = '号码是:' + response[0] + '<br>姓名是:' + response[1] + '<br>性别是:' + response[2] + '<br>职务是:' + response[3];    alert("响应服务完成!");    }    else if (xmlHttp.status == 404) {    alert('请求的网址不存在!');    }    else {    alert('错误:错误代码为:' + xmlHttp.status);    }  } } </script> <input id="qq" type="text" onchange="getCustomerInfo()" /> <div id="message">请尝试输入我的QQ号码:178010108,会看到返回的详细资料.</div>

服务端程序代码:

复制代码 代码如下:

<% Response.ContentType = "text/xml" Response.CharSet = "GB2312" if request("qq") = "178010108" then response.write "178010108|阿里西西|男|ASP技术" else response.write "这个QQ号码是空号哦" end if %>