为什么我的第二个下拉框怎么没数据呢?
HTML 如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=bgk" />
<title>无标题文档</title>
</head>
<script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#nr").val()?$("#province").append("<option value="+$("#nr").val()+">"+$("#nr").val()+"</option>"):alert("请输入内容");$("#nr").focus();
})
$("#province").change(function(){
var selecttd= $(this).find("option:selected").text();
$("#db").empty();
$("#db").append("<option value='请选择'>请选择</option>");
$.ajax({
type:"post",
url:"p.php",
data:{"p":selecttd},
dataType:"json",
success:function(json){
$.each(json,function(i,k){
//$("#DropRegion").empty();
$("#db").append("<option value="+k+">"+k+"</option>");
})
}
})
})
})
</script>
<body>
<select id="province">
<option>请选择主机</option>
<option value="all">选择</option>
<option value="1">TEST</option>
<option value="4">NOWS</option>
<option value="7">DB</option>
</select>
<select id="DB">
<option>请选择DB</option>
</select>
<input type="text" name="nr" id="nr"/><button>提交</button></br>
</body>
</html>
p.php
<?php
header("Content-Type:text/html;charset=bgk");
include_once('../../db/db_mssql.php');
$type=$_POST['p'];
switch($type)
{
case "":
$names = array("all");
break;
case "all":
$names = array("all");
break;
default:
$sqlser='select max(ser_name) dy from allserver where id='.$type;
$sqlname=sqlsrv_query($conn,$sqlser);
$ser=sqlsrv_fetch_array($sqlname);
$sqlser1="select [数据库] db_name from diskinfo where [计算机名]='".$ser["dy"]."' group by [数据库] " ;
$sqldb=sqlsrv_query($conn,$sqlser1);
$row=array();
//echo $sqlser1;
while($row=sqlsrv_fetch_array($sqldb)){
$names[]=$row["db_name"];
}
}
echo json_encode($names);
?>
------解决方案--------------------
$sqlser='select max(ser_name) dy from allserver where id='.$type;
sql语句错了吧,你发送的是select的文本内容是string类型的,导致sql语句出错了,应该是id
// var selecttd= $(this).find("option:selected").text();
var selecttd= $(this).val()////
------解决方案--------------------
你传的$type 好像是个显示名称 ,你拿来和id关联 对?
$sqlser='select max(ser_name) dy from allserver where id='.$type;