求php+ajax二级联菜 求php+ajax二级联菜 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 index.html文件-----------------------<script language="javascript" src="ajaxmenu.js"></script><html><head><meta http-equiv="Content-Type" c /><title>ajax2级联动菜单演示</title></head><body><form name="form1"><select name="select1" id="class1" style="width:100;" ><option value="1">大类1</option> <option value="2">大类2</option></select><select name="select2"id="class2" style="width:100;" ></select><select name="select3"id="class3" style="width:100;"></select></form></body></html>----------------------------列表的VALUE不能设置为中文----------------------------------ajaxmenu.js文件代码var http_request=false; function send_request(url){//初始化,指定处理函数,发送请求的函数 http_request=false; //开始初始化XMLHttpRequest对象 if(window.XMLHttpRequest){//Mozilla浏览器 http_request=new XMLHttpRequest(); if(http_request.overrideMimeType){//设置MIME类别 http_request.overrideMimeType("text/xml"); } } else if(window.ActiveXObject){//IE浏览器 try{ http_request=new ActiveXObject("Msxml2.XMLHttp"); }catch(e){ try{ http_request=new ActiveXobject("Microsoft.XMLHttp"); }catch(e){} } } if(!http_request){//异常,创建对象实例失败 window.alert("创建XMLHttp对象失败!"); return false; } http_request.onreadystatechange=processrequest; //确定发送请求方式,URL,及是否同步执行下段代码 http_request.open("GET",url,true); http_request.send(null); } //处理返回信息的函数 function processrequest(){ if(http_request.readyState==4){//判断对象状态 if(http_request.status==200){//信息已成功返回,开始处理信息 document.getElementById(reobj).innerHTML=http_request.responseText; } else{//页面不正常 alert("您所请求的页面不正常!"); } } } function getclass(obj){ var pid=document.form1.select1.value; document.getElementById(obj).innerHTML="<option>loading...</option>"; send_request(pid); reobj=obj; }-------------------------------------------doclass.php 文件代码<?php header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码 $pid=$_REQUEST['pid']; $db=mysql_connect("localhost","root","123456"); //创建数据库连接 mysql_query("set names 'GBK'"); mysql_select_db("datas"); $sql="select * from types where type='$pid'"; $result=mysql_query($sql); //循环列出选项 while($rows=mysql_fetch_array($result)){ echo '<option> '; echo $rows['tname']; echo "</option>\n"; }?>楼主你试一试吧.... 我是用xajax实现的,根据需求自己改的代码LZ可以上网搜下相关信息,看对你有没有帮助 http://hi.baidu.com/zjstandup/blog/item/040d2b468ec18c0c6a63e5ce.html数据很大么?一定要用ajax么? 将数据用php读出来,再用js来分类。很容易的。而且也不一定要 用ajax,有啥好玩的。 php+mysql输出的问题 关于采集后对数据编码转换的问题!请教! 如何把下面的JS转换成PHP变量值,php和JS的问题!求高人帮忙! php---gd库 PDO::exec()返回值的问题。 关于服务器IIS的域名设置问题 谁知道PHP怎么连接PROGRESS数据库 关于php定制导航 并生成链接 别人可以访问 怎么把获得的xml原样的返回到客户端? 上传错在那? 诚聘WEB开发设计师:高薪+机会+空间 不同数据库的数据能互相导数据吗?
-----------------------<script language="javascript" src="ajaxmenu.js"></script>
<html>
<head>
<meta http-equiv="Content-Type" c />
<title>ajax2级联动菜单演示</title>
</head><body>
<form name="form1">
<select name="select1" id="class1" style="width:100;" >
<option value="1">大类1</option>
<option value="2">大类2</option>
</select>
<select name="select2"id="class2" style="width:100;" >
</select>
<select name="select3"id="class3" style="width:100;">
</select>
</form>
</body>
</html>
----------------------------
列表的VALUE不能设置为中文
----------------------------------ajaxmenu.js文件代码var http_request=false;
function send_request(url){//初始化,指定处理函数,发送请求的函数
http_request=false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest){//Mozilla浏览器
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){//设置MIME类别
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){//IE浏览器
try{
http_request=new ActiveXObject("Msxml2.XMLHttp");
}catch(e){
try{
http_request=new ActiveXobject("Microsoft.XMLHttp");
}catch(e){}
}
}
if(!http_request){//异常,创建对象实例失败
window.alert("创建XMLHttp对象失败!");
return false;
}
http_request.onreadystatechange=processrequest;
//确定发送请求方式,URL,及是否同步执行下段代码
http_request.open("GET",url,true);
http_request.send(null);
}
//处理返回信息的函数
function processrequest(){
if(http_request.readyState==4){//判断对象状态
if(http_request.status==200){//信息已成功返回,开始处理信息
document.getElementById(reobj).innerHTML=http_request.responseText;
}
else{//页面不正常
alert("您所请求的页面不正常!");
}
}
}
function getclass(obj){
var pid=document.form1.select1.value;
document.getElementById(obj).innerHTML="<option>loading...</option>";
send_request(pid);
reobj=obj;
}-------------------------------------------
doclass.php 文件代码<?php
header("Content-type: text/html;charset=GBK");//输出编码,避免中文乱码
$pid=$_REQUEST['pid'];
$db=mysql_connect("localhost","root","123456"); //创建数据库连接
mysql_query("set names 'GBK'");
mysql_select_db("datas");
$sql="select * from types where type='$pid'";
$result=mysql_query($sql);
//循环列出选项
while($rows=mysql_fetch_array($result)){
echo '<option> ';
echo $rows['tname'];
echo "</option>\n";
}
?>楼主你试一试吧....