ajax+DropListDown联动

lishijie910123 2007-06-16 05:28:34
如何用ajax实现DropListDown的二级联动
(DropListDown的数据要求是从数据库中读出来滴)
...全文
370 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
自然框架 2011-02-25
  • 打赏
  • 举报
回复
这里有封装好的控件,n级联动,有源码。有省市区县的数据库
http://topic.csdn.net/u/20110225/16/1aae774d-e92e-4d1f-9065-61b712063c28.html?44405
yangdj2000 2007-06-19
  • 打赏
  • 举报
回复
php读取数据的操作:
<?php

$host="192.168.0.22";
$user="root";
$pwd="123456";
$database="edu_brochure";
$conn=mysql_connect($host,$user,$pwd) or die ("无法连接到数据库服务器,请联系我们".mysql_error());
$db=mysql_select_db($database,$conn) or die ("无法连接到数据库,请联系我们".mysql_error());
$co=$_REQUEST['collegetype'];
//$co="10";
$selectcollegeenamestr="select distinct(collegename) from college where collegetype=(select collegetype from college where collegeid='".$co."'".")";
//echo $selectcollegeenamestr;
$result=mysql_query($selectcollegeenamestr,$conn);
$num = mysql_num_rows($result);
//echo $num;
$arraycollegename=array();
while($row=mysql_fetch_array($result))
{
array_push($arraycollegename,$row[0]);
}
while(List($key,$value)=each($arraycollegename))
{
$charstr.=$value."|";
}
//echo $charstr;
?>
yangdj2000 2007-06-19
  • 打赏
  • 举报
回复
没人知道啊 ?

这是我今天又改的代码,还是有问题,大家帮忙看看啊

<html>
<head>
</head>
<?php
//include('MSAjaxService.php');
$host="192.168.0.22";
$user="root";
$pwd="123456";
$database="edu_brochure";
$conn=mysql_connect($host,$user,$pwd) or die ("无法连接到数据库服务器,请联系我们".mysql_error());
$db=mysql_select_db($database,$conn) or die ("无法连接到数据库,请联系我们".mysql_error());
?>
<script language="javascript">
function Setcollegetypename(value)
{
//var dptype = document.getElementById("selectcollegename").value;
var ur="find_collegename.php?collegetype="+value;
//alert(ur);
send_request(ur);
}
//String.prototype.trim = function()
//{
// return this.replace(/(^\s*)|(\s*$)/g, "");
//}
var http_request=false;
function send_request(url){
http_request=false;
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}

}
if(!http_request){
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
http_request.onreadystatechange=processRequest;
http_request.open("GET",url,true);
http_request.send(null);
}

function processRequest(){
if(http_request.readyState==4){
if(http_request.status==200){
var response = request.responseText.split("|");
alert(response);
var num = response[0];
while(var i = 0;i<=num+1;i++)
{
document.getElementbyid("providers").innerHTML=response[1];
}

}
else{
alert("您所请求的页面有异常!");
}
}
}

</script>
<body>
<table><tr><td>
</td></tr>
<tr><form id="sdg" name="FormData" method="post">
<td height="25" align="right">院校类型
</td>
<td width="112" height="25" align="left"><label>


<select name="selectcollegename" onchange="Setcollegetypename(FormData.selectcollegename.value)">
<option value="">选择类型...</option>
<?php
$collegetypeselectstr="select distinct(collegetype) from college";
$collegetypeselect=mysql_query($collegetypeselectstr,$conn);
while($rowcollege=mysql_fetch_row($collegetypeselect))
{
$str="select collegeid from college where collegetype="."'$rowcollege[0]'";
echo $str;
$re=mysql_query($str,$conn);
$e=mysql_fetch_array($re);
echo "<option value=".$e[0].">";
echo $rowcollege[0]."</option>";
}
?>
</select>

</label></td></form>
</tr>
<tr><form id="asd" name="form2" method="post">
<td height="."25"." align="."right".">院校名称</td>
<td height="."25"." align="left"left".">
<select name="providers" onChange="getCustomerInfo()">
<?
while($row = @mysql_fetch_array($result))
{
?>
<option value="<? echo $row["dp_name"] ?>" selected>选择名称... <? echo $row[0] ?></option>
<? }?>
</select>

</td></form>
</table>
</body>
</html>
yangdj2000 2007-06-18
  • 打赏
  • 举报
回复
我 也 需要 这个 方面 的 我 的 第一个菜单的 值也 是 从 数据库里读出 来 的 ,然后 根据上边的动态查询数据库里的 值产生,这是我的 表结构

学校名称 学校类型 课程名称 课程类型

----------------------
清华大学 理工 计算机 工程

我已经 能将学校类型传到 下一个页面了,这个页面是 处理从 数据库里 读取的所有理工类学校的名称的 ,现在的问题是我读取后的学校名称怎么样传到前边的下拉菜单里啊 ?

原程序如下:

<html>
<head>
</head>
<?php
//include('MSAjaxService.php');
$host="192.168.0.22";
$user="root";
$pwd="123456";
$database="edu_brochure";
$conn=mysql_connect($host,$user,$pwd) or die ("无法连接到数据库服务器,请联系我们".mysql_error());
$db=mysql_select_db($database,$conn) or die ("无法连接到数据库,请联系我们".mysql_error());
?>
<script language="javascript">
function Setcollegetypename(value)
{
var ur="find_collegename.php?collegetype="+value;
send_request(ur);
}
String.prototype.trim = function()
{
return this.replace(/(^\s*)|(\s*$)/g, "");
}
var http_request=false;
function send_request(url){
http_request=false;
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
if(http_request.overrideMimeType){
http_request.overrideMimeType("text/xml");
}
}
else if(window.ActiveXObject){
try{
http_request=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
http_request=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}

}
if(!http_request){
window.alert("不能创建XMLHttpRequest对象实例!");
return false;
}
http_request.onreadystatechange=processRequest;
http_request.open("POST",url,true);
http_request.send(null);
}

function processRequest(){
if(http_request.readyState==4){
if(http_request.status==200){
alert(unescape(http_request.responseText.trim()));
doactions(http_request.responseText.trim());
}
else{
alert("您所请求的页面有异常!");
}
}
}

</script>
<body>
<table><tr><td>
</td></tr>
<tr><form id="sdg" name="FormData" method="post">
<td height="25" align="right">院校类型
</td>
<td width="112" height="25" align="left"><label>


<select name="selectcollegename" onchange="Setcollegetypename(FormData.selectcollegename.value)">
<option value="">选择类型...</option>
<?php
$collegetypeselectstr="select distinct(collegetype) from college";
$collegetypeselect=mysql_query($collegetypeselectstr,$conn);
while($rowcollege=mysql_fetch_row($collegetypeselect))
{
$str="select collegeid from college where collegetype="."'$rowcollege[0]'";
echo $str;
$re=mysql_query($str,$conn);
$e=mysql_fetch_array($re);
echo "<option value=".$e[0].">";
echo $rowcollege[0]."</option>";
}
?>
</select>

</label></td></form>
</tr>
<tr><form id="asd" name="form2" method="post">
<td height="."25"." align="."right".">院校名称</td>
<td height="."25"." align="left"left".">
<select name="providers" >
<option value="">选择名称...</option>
</select>
</td></form>
</tr><tr><td>
<?php
$ww="select collegename from college where collegetype='理工'";
$re=mysql_query($ww,$conn);
$array1=array();
while($row=mysql_fetch_array($re))
{
array_push($array1,$row[0]);
}
$arr=&$array1;
while(list($key,$value)=each($arr))
{
echo "$key:$value<br>";
}
?>
</td></tr>
</table>
</body>
</html>


读取学校名称的代码 :

<html>
<head>
<title></title>
<body>

<?php

$host="192.168.0.22";
$user="root";
$pwd="123456";
$database="edu_brochure";
$conn=mysql_connect($host,$user,$pwd) or die ("无法连接到数据库服务器,请联系我们".mysql_error());
$db=mysql_select_db($database,$conn) or die ("无法连接到数据库,请联系我们".mysql_error());
$co=$_REQUEST['collegetype'];
//$co="1";
$selectcollegeenamestr="select collegename from college where collegetype=(select collegetype from college where collegeid='".$co."'".")";
//echo $selectcollegeenamestr;
$result=mysql_query($selectcollegeenamestr,$conn);
$arraycollegename=Array();
while($row=mysql_fetch_array($result))
{
array_push($arraycollegename,$row[0]);
}
while(List($key,$value)=each($arraycollegename))
{
//echo "$key:$value<br>";
$charstr.=$value."|";

}
echo $charstr;
//echo $charstr."<br>";
?>
</body>
</html>

学校名称就存在$charstr里 ,那位大哥有更 好 的 实现方法告诉 我一声啊 就是两个菜单都是动态从数据库里 读取 ,然后第二个菜单根据第一个菜单而级联?好 心大哥帮帮忙啊 !
lishijie910123 2007-06-18
  • 打赏
  • 举报
回复
小弟刚学AJAX希望个为能给出源码,
好让我研究研究....谢谢拉
liu_87663663 2007-06-17
  • 打赏
  • 举报
回复
就是一个异步提交撒

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧