search
Homephp教程php手册php的ajax联动菜单

php的ajax联动菜单

Jun 13, 2016 am 10:36 AM
ajaxinijavascriptlanguagephpscriptsrcofLinkagemenu

main.php

<script><br /> <!--<br /> <br /> function getoption(select1,target)<br /> {<br /> if(select1.value!=0){<br /> //select1是提交数据的来源的select菜单名<br /> var url = "getoption.php?pid="+select1.value;//取得xml的url<br /> //alert(url);<br /> var ajax = InitAjax();<br /> var i = 0;<br /> ajax.open("GET", url, true);<br /> ajax.onreadystatechange = function() {<br /> //如果执行是状态正常,那么就把返回的内容赋值给指定的地方<br /> if (ajax.readyState == 4 && ajax.status == 200) {<br /> var obj = ajax.responseXML;<br /> var properties = obj.getElementsByTagName("property");<br /> var name,value;<br /> target.options.length = 1;<br /> for (var i=0,x=1;i<properties.length;i++,x++) {<br /> name = properties[i].getElementsByTagName("name")[0].firstChild.nodeValue;<br /> value = properties[i].getElementsByTagName("value")[0].firstChild.nodeValue;<br /> target.options[x] = new Option();<br /> target.options[x].text = name;<br /> target.options[x].value = value;<br /> }<br /> }<br /> }<br /> ajax.send(null);<br /> }<br /> }<br /> <br /> <br /> <form method="post" name="form" action="index.php"><br /> <select name="level1" onchange="getoption(document.form.level1,document.form.level2);"/><br /> <option selected="ture" value="0">===选择===<br /> <?<br /> if ($nrows>0){<br /> for ($i=0;$i<$nrows;$i++){<br /> echo "<option value="{$results[ID][$i]}">{$results[NAME][$i]}";<br /> }<br /> }<br /> ?><br /> <br /> <select name="level2" onchange="getoption(document.form.level2,document.form.level3);"><br /> <option selected="ture" value="0">===选择===<br /> <br /> <br /> iniajax.js:<br /> function InitAjax()<br /> {<br /> var ajax=false;<br /> try {<br /> ajax = new ActiveXObject("Msxml2.XMLHTTP");<br /> } catch (e) {<br /> try {<br /> ajax = new ActiveXObject("Microsoft.XMLHTTP");<br /> } catch (E) {<br /> ajax = false;<br /> }<br /> }<br /> if (!ajax && typeof XMLHttpRequest!=undefined) {<br /> ajax = new XMLHttpRequest();<br /> }<br /> return ajax;<br /> }<br /> <br /> getoption.php:<br /> <?php<br /> if($pid=$_GET["pid"])<br /> {<br /> header("Content-type: text/xml;charset=GB2312");<br /> echo "<?xml version="1.0" encoding="GB2312"?>";<br /> include("./oracle.inc");<br /> $sql="select * from AJAXTEST where PARENTID = $pid";<br /> //echo $sql;<br /> $stmt=ociparse($handle,$sql);<br /> ociexecute($stmt);<br /> ocicommit($handle);<br /> ocilogoff();<br /> $nrows=ocifetchstatement($stmt,$results);<br /> echo "<properties>";<br /> //echo "<row>{$nrows}";<br /> for ($i=0;$i<$nrows;$i++){<br /> echo "<property>";<br /> echo "<value>{$results[ID][$i]}";<br /> echo "<name>{$results[NAME][$i]}";<br /> echo "";<br /> }<br /> echo "";<br /> }<br /> ?></script>

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool