<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script src="WebUI/js/clienthint.js"></script>
</head>
<body>
<form>
First Name:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html
1 var xmlHttp
2 function showHint(str) {
3 if (str.length == 0) {
4 document.getElementById("txtHint").innerHTML = "";
5 return;
6 }
7 xmlHttp =ttpObject()
8 if (xmlHttp == null) {
9 alert("您的浏览器不支持ajax");
10 return;
11 }
12 var url = "getint.aspx";
13 url = url + "?q=" + str;
14 url += "&sid=" + Math.random();
15 xmlHttp.onreadystatechange= stateChanged;
16 xmlHttp.open("GET", url, true);
17 xmlHttp.send(null);
18
19 }
20 function stateChanged() {
21
22 if (xmlHttp.readyState == 4) {
23 console.log(xmlHttp.responseText);
24 document.getElementById("txtHint").innerHTML = xmlHttp.responseText;
25
26 }
27 }
28 function ttpObject() {
29 var xmlHttp = null;
30 try{
31 xmlHttp=new XMLHttpRequest();
32
33 }
34 catch (e) {
35 try{
36 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
37 }
38 catch (e) {
39 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
40
41 }
42 }
43 return xmlHttp;
44
45 }
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7
8 namespace DemoItem
9 {
10 public partial class getint : System.Web.UI.Page
11 {
12 protected void Page_Load(object sender, EventArgs e)
13 {
14 string q = Request.QueryString["q"].ToString();
15 Response.Write(q);
16 Response.End();//终止执行代码
17
18 }
19 }
20 }