1.ajax.html
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Title> Ajax </title>
<SCRIPT type = "text/JavaScript">
Function loadxmldoc (txt ){
VaR XMLHTTP;
If (window. XMLHttpRequest) {// code for IE7 +, Firefox, chrome, opera, Safari
XMLHTTP = new XMLHttpRequest ();
}
Else {// code for IE6, ie5
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
XMLHTTP. onreadystatechange = function (){
If (XMLHTTP. readystate = 4 & XMLHTTP. Status = 200 ){
VaR citys = XMLHTTP. responsetext. Split (',');
Document. getelementbyid ("citys"). Length = 1;
For (I = 0; I <Citys. Length-1; I ++ ){
Document. getelementbyid ("citys"). Add (New Option (citys [I], citys [I]);
}
// Document. getelementbyid ("mydiv"). innerhtml = XMLHTTP. responsetext;
}
}
XMLHTTP. Open ("get", "ajax/getdata. aspx? Pro = "+ txt, true );
XMLHTTP. Send ();
}
</SCRIPT>
</Head>
<Body>
<H2> Ajax </H2>
<Select id = "select1" onchange = "loadxmldoc (this. Value)">
<Option> select a province </option>
<Option value = "1"> Jiangsu </option>
<Option value = "2"> Shanghai </option>
</SELECT>
<Select id = "citys">
<Option> select a city </option>
</SELECT>
<Div id = "mydiv"> </div>
</Body>
</Html>
2. getdata. aspx. CS
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Public partial class ajax_getdata: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
String [] JS = new string [] {"Nanjing", "Suzhou", "Changzhou", "Wuxi", "Zhenjiang "};
String pro = request. querystring ["pro"];
If (PRO = "1 ")
{
String temp = "";
For (INT I = 0; I <Js. length; I ++)
{
Temp = temp + JS [I];
Temp = temp + ",";
}< br> response. write (temp);
}< br> else
response. write ("");
}< BR >}