我尝试构建使用 ajax 更改第二个选择框的值的选择框。
首先,我选择 AREA 而不是该地区的 CITIES。
你能告诉我我做错了什么吗?
客户端:
<script>
$(function () {
$("#first").change(function () {
$("#second").load('recs.php?area_id=' + $(this).val());
});
});
</script>
<form method="post" action="tosomewhere.php">
<select id="first" name="area_id">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select id="second" name="section"> </select>
</form>
服务器端:
<?PHP
include "db.php"
$areaID = $_GET['area_id'];
$second_option = "";
$query2 = mysql_query("SELECT * FROM `cities` WHERE area_id = $areaID ORDER BY id ASC");
while($index = mysql_fetch_array($query2))
{
$id = $index['id'];
$name = $index['name'];
$second_option .= "<option value='$id'>$name</option>";
}
echo $second_option;
?>