The remaining parts have not been written, and the subsequent parts can be completed by yourself. Database connection is not performed, and you need to connect to the database on your own.
ReferenceCode:
Showcity.html
<! Doctype HTML public " -// W3C // dtd html 4.01 transitional // en " > <HTML> " Content-Type " Content = " Text/html; charset = UTF-8 " > <! -- <LINK rel = " Stylesheet " Type = " Text/CSS " Href = " Styles.css " > --> <SCRIPT type = " Text/JavaScript " > // Create an Ajax Engine Function getxmlhttprequest (){ VaR XMLHTTP; If (Window. activexobject) {XMLHTTP = New Activexobject ( " Microsoft. XMLHTTP " ); // Window. Alert ("ie "); } Else {XMLHTTP = New XMLHttpRequest ();} Return XMLHTTP ;} // Sendrequest VaR XMLHttpRequest; function sendrequest (){ // Get the XMLHTTPRequest object XMLHttpRequest = Getxmlhttprequest (); VaR Url = " /Ajax/citylist. php " ; VaR Data = " Province = " + $ ( ' Sheng ' ). Value; // Window. Alert (data ); XMLHttpRequest. Open ( " Post " , URL, True ); // This sentence must be added for post submission. XMLHttpRequest. setRequestHeader ( " Content-Type " , " Application/X-WWW-form-urlencoded " ); // Callback Function XMLHttpRequest. onreadystatechange = Function chuli (){ If (XMLHttpRequest. readystate = 4 ){ If (XMLHttpRequest. Status = " 200 " ){ // Retrieve results VaR Citys = XMLHttpRequest. responsexml. getelementsbytagname ( " City " ); $ ( ' City ' ). Length = 0 ; VaR Myoption = Document. createelement ( " Option " ); Myoption. innertext = " -- City -- " ; $ ( ' City ' ). Appendchild (myoption ); // Window. Alert (Citys. Length ); // Traversal For ( VaR I = 0 ; I <Citys. length; I ++ ){ // Window. Alert (citys [I]. childnodes [0]. nodevalue ); VaR City_name = citys [I]. childnodes [ 0 ]. Nodevalue; // Create new elements VaR Myoption = Document. createelement ( " Option " ); Myoption. Value = City_name; myoption. innertext = City_name; $ ( " City " ). Appendchild (myoption );}}}} // Send data XMLHttpRequest. Send (data);} function $ (ID ){ Return Document. getelementbyid (ID );} </SCRIPT> Select Id = " Sheng " Onchange = " Sendrequest (); " > <Option value = "" > --- Save --- </option> <option value = " Hunan " > Hunan </option> <option value = " Jiangsu " > Jiangsu </option> </ Select > < Select Id = " City " > <Option value ="" > -- City -- </option> </ Select > < Select Id = " County " > <Option value = "" > -- County -- </option> </ Select > </Body>
Citylist. php
<? PHP // The first speech tells the browser that the returned data is in XML format. Header ( " Content-Type: text/XML; charset = UTF-8 " ); // Tell the browser not to cache data Header ( " Cache-control: No-Cache " ); // Receive $ Province = $ _ post [ ' Province ' ]; // Debugging File_put_contents ( " D:/mylog. Log " , $ Province. " \ R \ n " , File_append); $ result = "" ; If ($ Province = " Hunan " ) {$ Result =" <Province> <city> Changsha </city> <city> Yueyang </city> <city> Hengyang </city> </province> " ;} Else If ($ Province = " Jiangsu " ) {$ Result = " <Province> <city> Nanjing </city> <city> Yancheng </city> <city> Suzhou </city> </province> " ;} Echo $ result; ?>