我正在尝试在表单中创建一个动态填充的下拉列表以进行位置选择。我已经在其他提出类似问题的帖子和一些网站中搜索过堆栈,但我的第二个下拉列表始终为空。
第一个下拉列表是通过 MySQL 查询填充的。
表格部分
<label for="" class="block">District
<select id="dists" name="prop_district" class="full block" required>
<option selected disabled>District...</option>
<?php
$dist = new Database();
$dist->getDistricts();
?>
</select>
</label>
<label for="" class="block">Council
<select id="p_councils" name="prop_council" class="full block" required>
<option selected disabled>Council...</option>
</select>
</label>
阿贾克斯请求
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#dists").change(function(){
var id=$(this).val();
$.ajax({
type: "GET",
url: "includes/scripts/ajax/ajax_county.php",
data: { district : $("#dists").val() },
success: function(reply){
$("#councils").html(reply);
console.log(reply);
},
error: function() {
alert('Error occured');
}
});
});
});
</script>
ajax_county.php
<?php
if(isset($_POST['district'])){
$district = $_POST['district'];
$dist = new Database();
$dist->getCouncils($district);
}else{
echo"fail";
}
?>
小唯快跑啊