1.ajax.html
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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>
<body>
<select id= "Select1" onchange= "Loadxmldoc (this.value)" >
<option> Please select Province </option>
<option value= "1" > Jiangsu </option>
<option value= "2" > Shanghai </option>
</select>
<select id= "Citys" >
<option> Please select City </option>
</select>
<div id= "Mydiv" ></div>
</body>
2.getdata.aspx.cs
Copy Code code as follows:
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 + ",";
}
Response.Write (temp);
}
Else
Response.Write ("");
}
}