Client code:
Copy codeThe Code is as follows:
<! 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>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> untitled document </title>
</Head>
<Script type = "text/javascript">
Var xmlHttp;
Var a = new Array ();
Function createXMLHttpRequest (){
If (window. ActiveXObject ){
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
}
Function send_request (){
CreateXMLHttpRequest ();
Var year = document. getElementById ("year ");
Var url = "check_2.php? Page = "+ escape (year. value );
XmlHttp. open ("GET", url, true );
XmlHttp. onreadystatechange = checkit;
XmlHttp. send (null );
}
Function checkit (){
If (xmlHttp. readystate = 4 ){
If (xmlHttp. status = 200 ){
ShowChild ();
}
}
}
Function showChild (){
Var xmlDoc = xmlHttp. responseXML;
Var content = xmlDoc. getElementsByTagName ("city ");
For (var I = 0; I <content. length; I ++ ){
Var y = content [I];
A [I] = y. childNodes [0]. data;
}
Show1 ();
}
Function show1 (){
Var obj = document. getElementById ("name ");
Var number = obj. length;
For (var j = obj. length-1; j> = 0; j --){
Obj. removeChild (obj. childNodes. item (j ));
}
For (var I = 0; I <a. length; I ++ ){
Var opt = document. createElement ("OPTION ");
Opt. text = a [I];
Obj. add (opt );
}
}
</Script>
<Body>
Year: <select id = "year" onchange = "send_request ()">
<Option value = "0"> select </option>
<Option value = "1"> 1996-2006 </option>
<Option value = "2"> 1986-1995 </option>
<Option value = "3"> 1971-1985 </option>
<Option value = "4"> 1970 or earlier </option>
</Select>
Subdirectory: <select id = "name">
<Option value = "0"> select </option>
</Select>
</Body>
</Html>
Server code:
Copy codeThe Code is as follows:
<? Php
Header ('content-type: text/xml ');
$ Xml = "<? Xml version = '1. 0' encoding = 'gb2312 '?> ";
$ Year = $ _ GET ["page"];
$ Content = $ xml. "<contents> ";
If ($ year = "1 "){
$ Content = $ content. "<city> 1 </city> <city> 11 </city> </contents> ";
}
Else if ($ year = '2 '){
$ Content = $ content. "<city> 2 </city> <city> 12 </city> </contents> ";
}
Else if ($ year = '3 '){
$ Content = $ content. "<city> 3 </city> <city> 13 </city> </contents> ";
}
Else if ($ year = '4 '){
$ Content = $ content. "<city> 4 </city> <city> 14 </city> </contents> ";
}
Echo $ content;
?>