Ajax-Level Linkage menu code

Source: Internet
Author: User

Ajax-Level Linkage menu code
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
&LT;TITLE&GT;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>

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.