Ajax-Level Linkage menu code
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<TITLE>AJAX2 Level Linkage Menu Demo </title>
<script language= "JavaScript" >
var Http_request=false;
function send_request (URL) {//initialization, specifying handler functions, sending requested functions
Http_request=false;
Start initializing the XMLHttpRequest object
if (window. XMLHttpRequest) {//mozilla browser
Http_request=new XMLHttpRequest ();
if (http_request.overridemimetype) {//Set MIME category
Http_request.overridemimetype ("Text/xml");
}
}
else if (window. ActiveXObject) {//ie browser
try{
Http_request=new ActiveXObject ("msxml2.xmlhttp");
}catch (e) {
try{
Http_request=new ActiveXObject ("Microsoft.XMLHTTP");
}catch (e) {}
}
}
if (!http_request) {//exception, failed to create object instance
Window.alert ("Create XMLHTTP object failed!") ");
return false;
}
Http_request.onreadystatechange=processrequest;
Determine how to send the request, the URL, and whether to execute the next code synchronously
Http_request.open ("Get", url,true);
Http_request.send (NULL);
}
Functions that process return information
function ProcessRequest () {
if (http_request.readystate==4) {//Judge object state
if (http_request.status==200) {//information returned successfully, start processing information
document.getElementById (reobj). Innerhtml=http_request.responsetext;
}
else{//page is not normal
Alert ("The page you requested is not normal!") ");
}
}
}
function GetClass (obj) {
var Pid=document.form1.select1.value;
document.getElementById (obj). innerhtml= "<option>loading...</option>";
Send_request (' doclass.php?pid= ' +pid);
Reobj=obj;
}
</script>
<body>
<form name= "Form1" >
<select name= "Select1" id= "Class1" style= width:100 "onchange=" getclass (' class2 '); " >
<option selected= "Selected" ></option>
<option value= "1" > Big class 1</option>
<option value= "2" > Big class 2</option>
</select>
<select name= "Select2" id= "Class2" style= "width:100"; >
</select>
</form>
<?php
Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=GBK")//output encoding to avoid Chinese garbled
$pid =$_get[' pid '];
$db =mysql_connect ("localhost", "root", "7529639"); Creating a database connection
mysql_query ("Set names ' GBK '");
mysql_select_db ("Menuclass");
$sql = "Select classname from Menu where parentid=". $pid. "";
$result =mysql_query ($sql);
Looping list options
while ($rows =mysql_fetch_array ($result)) {
Echo ' <option> ';
echo $rows [' classname '];
echo "</option>n";
}
?>
</body>