我有两个选择框。根据firstbox中选择的值,secondbox将从mysql数据库中填充值。我谷歌很多,但我没有找到答案,任何人都可以给我建议/解决方案。
我的代码: 首先选择框:
<select name="specialities" id="specialities">
<option value="select">-------select-------</option>
<option value="psychiatry">psychiatry</option>
<option value="sleep">sleep</option>
<option value="nuerology">nuerology</option>
<option value="pulmonary">pulmonary</option>
<option value="git">git</option>
<option value="general">general</option>
<option value="ent">ent</option>
<option value="cvs">cvs</option>
<option value="breast">breast</option>
<option value="reproductive_male">reproductive_male</option>
<option value="reproductive_female">reproductive_female</option>
</select>
这是要从db中填充数据的div:
<div>
<select id="main">
<option>----------------------------</option>
</select>
</div>
我的选择框填充的jquery代码:
<script>
$(document).ready(function() {
$("#specialities").change(function(){
var spl = $(this).val();
$.ajax(
"doctor_details.php",
{spl : "spl"},
function(data) {
$('#main').html(data);
});
</script>
我的php页面doctor_details.php:
$sql = "select * from doc_work_details where specalities='$_REQUEST[spl]'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo '<option>'.$row['firstname'].' '.' '.' '. $row['qualification']. ' '.' '.' '
.$row['specialization'].'</option>';
}
提前谢谢你 Ramsai
答案 0 :(得分:0)
我不是jQuery的专家,但是在你的doctor_details.php
页面中,你是否回应了
<select> .... </select>
之前和之后?
答案 1 :(得分:0)
调用$ .ajax()API的典型方法是例如
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});