案例:ajax案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function showHint(str)
5
{
6
var xmlhttp;
7
if (str.length==0)
8
  { 
9
  document.getElementById("txtHint").innerHTML="";
10
  return;
11
  }
12
if (window.XMLHttpRequest)
13
  {// code for IE7+, Firefox, Chrome, Opera, Safari
14
  xmlhttp=new XMLHttpRequest();
15
  }
16
else
17
  {// code for IE6, IE5
18
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
19
  }
20
xmlhttp.onreadystatechange=function()
21
  {
22
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
23
    {
24
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
25
    }
26
  }
27
xmlhttp.open("GET","/example/aspnet/gethint.aspx?q="+str,true);
28
xmlhttp.send();
29
}
30
</script>
31
</head>
32
<body>
33
34
<h3>请在下面的输入框中键入字母(A - Z):</h3>
35
<form action=""> 
36
姓氏:<input type="text" id="txt1" onkeyup="showHint(this.value)" />
37
</form>
38
<p>建议:<span id="txtHint"></span></p> 
39
40
</body>
41
</html>