Php ajax linkage menu

Source: Internet
Author: User

Main. php
<Script language = "javascript" src = "initajax. js"> </script> <! -- InitAjax () -->
<Script>
<! --

Function getoption (select1, target)
{
If (select1.value! = 0 ){
// Select1 is the select menu name of the source for data submission.
Var url = "getoption. php? Pid = "+ select1.value; // get the xml url
// Alert (url );
Var ajax = InitAjax ();
Var I = 0;
Ajax. open ("GET", url, true );
Ajax. onreadystatechange = function (){
// If the execution is normal, the returned content is assigned to the specified place.
If (ajax. readyState = 4 & ajax. status = 200 ){
Var obj = ajax. responseXML;
Var properties = obj. getElementsByTagName ("property ");
Var name, value;
Target. options. length = 1;
For (var I = 0, x = 1; I <properties. length; I ++, x ++ ){
Name = properties [I]. getElementsByTagName ("name") [0]. firstChild. nodeValue;
Value = properties [I]. getElementsByTagName ("value") [0]. firstChild. nodeValue;
Target. options [x] = new Option ();
Target. options [x]. text = name;
Target. options [x]. value = value;
}
}
}
Ajax. send (null );
}
}


<Form method = "post" name = "form" action = "index. php">
<Select name = "level1" onchange = "getoption (document. form. level1, document. form. level2);"/>
<Option selected = "ture" value = "0" >== select ==</option>
<?
If ($ nrows> 0 ){
For ($ I = 0; $ I <$ nrows; $ I ++ ){
Echo "<option value =" {$ results [ID] [$ I]} ">{$ results [NAME] [$ I]} </option> ";
}
}
?>
</Select>
<Select name = "level2" onchange = "getoption (document. form. level2, document. form. level3);">
<Option selected = "ture" value = "0" >== select ==</option>
</Select>

Iniajax. js:
Function InitAjax ()
{
Var ajax = false;
Try {
Ajax = new ActiveXObject ("Msxml2.XMLHTTP ");
} Catch (e ){
Try {
Ajax = new ActiveXObject ("Microsoft. XMLHTTP ");
} Catch (E ){
Ajax = false;
}
}
If (! Ajax & typeof XMLHttpRequest! = Undefined ){
Ajax = new XMLHttpRequest ();
}
Return ajax;
}

Getoption. php:
<? Php
If ($ pid = $ _ GET ["pid"])
{
Header ("Content-type: text/xml; charset = GB2312 ");
Echo "<? Xml version = "1.0" encoding = "GB2312"?> ";
Include ("./oracle. inc ");
$ SQL = "select * from AJAXTEST where PARENTID = $ pid ";
// Echo $ SQL;
$ Stmt = ociparse ($ handle, $ SQL );
Ociexecute ($ stmt );
Ocicommit ($ handle );
Ocilogoff ();
$ Nrows = ocifetchstatement ($ stmt, $ results );
Echo "<properties> ";
// Echo "<row >{$ nrows} </row> ";
For ($ I = 0; $ I <$ nrows; $ I ++ ){
Echo "<property> ";
Echo "<value >{$ results [ID] [$ I]} </value> ";
Echo "<name >{$ results [NAME] [$ I]} </name> ";
Echo "</property> ";
}
Echo "</properties> ";
}
?>

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.