我试图在服务器端检索使用jQuery .load()
呼叫发送的selected option
的值:
<script type="text/javascript">
$(function () {
$("#first").change(function () {
$("#second").load('populate_section.php?year=', {first: $(this).val()});
});
});
</script>
<tr>
<td>
<select id="first" name="year">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
</select>
</td>
</tr>
<tr>
<td>
<select id="second" name="section">
</select>
</td>
</tr>
然后我如何尝试检索我的PHP
代码中的值:
<?php
$year = $_GET['year']; // for test only
echo "<option>" . $year . "</option>";
?>
我假设结果将是一个下拉框,其值是我在第一个下拉框中选择的值。然而,var $year
似乎是空的。
谢谢。
您没有为URL中的"year" GET变量设置任何值。如果您需要发送$(this).val()作为"year",请按照下面的代码进行操作。
$("#second").load('populate_section.php', {"year": $(this).val()});
试试这个:
$(function () {
$("#first").change(function () {
$("#second").load('populate_section.php', {year: $(this).val()});
});
});