我正在尝试根据另一个菜单中的选择填充第二个选项选择菜单。问题是,我无法让 jQuery 执行它。这是我的代码
<head>
<script type="text/javascript">
$(document).ready(function()
{
$("#add_subject").change(function()
{
var id=$(this).val();
var dataString = 'id='+ id;
$.ajax
({
type: "POST",
url: "inc.add.content.populate.php",
data: dataString,
cache: false,
success: function(html)
{
$("#add_content").html(html);
}
});
});
});
</script>
</head>
<div class="grid_10">
<div class="box round first">
<h2>Title</h2>
<div class="block">
<form method="post">
<table class="form">
<tr>
<td>
<select id="add_subject" name="add_subject">
<option value="1">first option</option>
</select>
<select id="add_content" name="add_content">
</select>
</td>
</tr>
</table>
</form>
</div>
</div>
</div>
还有我的 inc.add.content.populate.php 文件
<?php
require_once(BASEDIR.'includes'.DIRECTORY_SEPARATOR.'inc.functions.php');
if($_POST['id'])
{
$id=$_POST['id'];
global $mysqli;
if($query = $mysqli->prepare("SELECT naslov,vsebine_id FROM table_vsebine WHERE predmet_id=?")){
$query->bind_param('i',$id);
if($query->execute()){
$query->bind_result($naslov,$vsebine_id);
$query->store_result();
while($row = $query->fetch()){
echo '<option value="'.$vsebine_id.'">'.$naslov.'</option>';
}
}
}
}
?>