index.html:
- <html>
- <head>
- <title>AJAX教程实例-AJAX教程实例-ASP+AJAX</title>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- </head>
- <body>
- <script>
- var xmlHttp
- function showCustomer(str)
- {
- var url="getcustomer.asp?sid=" + Math.random() + "&q=" + str
- xmlHttp=GetXmlHttpObject(stateChanged)
- xmlHttp.open("GET", url , true)
- xmlHttp.send(null)
- }
- function stateChanged()
- {
- if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
- {
- document.getElementById("txtHint").innerHTML=xmlHttp.responseText
- }
- }
- function GetXmlHttpObject(handler)
- {
- var objXmlHttp=null
- if (navigator.userAgent.indexOf("Opera")>=0)
- {
- alert("This example doesn't work in Opera")
- return;
- }
- if (navigator.userAgent.indexOf("MSIE")>=0)
- {
- var strName="Msxml2.XMLHTTP"
- if (navigator.appVersion.indexOf("MSIE 5.5")>=0)
- {
- strName="Microsoft.XMLHTTP"
- }
- try
- {
- objXmlHttp=new ActiveXObject(strName)
- objXmlHttp.onreadystatechange=handler
- return objXmlHttp
- }
- catch(e)
- {
- alert("Error. Scripting for ActiveX might be disabled")
- return
- }
- }
- if (navigator.userAgent.indexOf("Mozilla")>=0)
- {
- objXmlHttp=new XMLHttpRequest()
- objXmlHttp.onload=handler
- objXmlHttp.onerror=handler
- return objXmlHttp
- }
- }
- </script>
- <form>请选择用户:
- <select name="customers" onchange="showCustomer(this.value)">
- <option value="1">阿里西西</option>
- <option value="2">哇塞网</option>
- <option value="3">收音机</option>
- </select>
- </form><p>
- <div id="txtHint"><b>用户信息...</b></div>
- </p></body>
- </html>
getcustomer.asp:
- <ul>
- <%
- response.write "<li>12312312</li>"
- response.write "<li>123</li>"
- response.write "<li>123123</li>"
- %>
- </ul>