案例:ajax案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<head>
3
<script type="text/javascript">
4
function showCustomer(str)
5
{
6
var xmlhttp;    
7
if (str=="")
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/ajax/getcustomer.aspx?q="+str,true);
28
xmlhttp.send();
29
}
30
</script>
31
</head>
32
<body>
33
34
<form action="" style="margin-top:15px;"> 
35
<label>请选择一位客户:
36
<select name="customers" onchange="showCustomer(this.value)" style="font-family:Verdana, Arial, Helvetica, sans-serif;">
37
<option value="APPLE">Apple Computer, Inc.</option>
38
<option value="BAIDU ">BAIDU, Inc</option>
39
<option value="Canon">Canon USA, Inc.</option>
40
<option value="Google">Google, Inc.</option>
41
<option value="Nokia">Nokia Corporation</option>
42
<option value="SONY">Sony Corporation of America</option>
43
</select>
44
</label>
45
</form>
46
<br />
47
<div id="txtHint">客户信息将在此处列出 ...</div>
48