AJAX Level two Cascade menu implementation code _AJAX related

Source: Internet
Author: User
Client code:
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 ">
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<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>
Years: <select id= "Year" onchange= "Send_request ()" >
<option value= "0" > Please select </option>
<option value= "1" >1996-2006</option>
<option value= "2" >1986-1995</option>
<option value= "3" >1971-1985</option>
<option value= "4" >1970 before </option>
</select>
Sub-directory: <select id= "Name" >
<option value= "0" > Please select </option>
</select>
</body>

Server-side code:
Copy Code code 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;
?>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.