如何在PHP中通过ajax获取下拉列表的值?
PHP代码:
如何使用ajax在不刷新页面的情况下从下拉列表中获取部门的值。
<select name="Department" id="Department" class="DropDown">
<?php
$sql = "select * from department_details";
$exec = mysql_query($sql);
echo "<option value='0'>Select</option>";
while($row = mysql_fetch_array($exec))
{
?>
<?php echo "<option value=\"".$row['DepartmentId']."\">".$row['DepartmentName']."</option> \n "; ?>
<?php } ?>
<option value="other">Other</option>
</select>
JavaScript代码:
<script>
$("#form").submit(function(event) {
event.preventDefault();
var $form = $( this ),
value1 = $form.find( 'input[name="ProfessorName"]' ).val(),
value2 = $form.find( 'input[name="Department"]' ).val(),
url = $form.attr( 'action' );
var posting = $.post( url, { ProfessorName: value1, Department: value2 } );
posting.done(function( data ) {
$( "#result" ).empty().append( data );
});
});
</script>
如何使用ajax在不刷新页面的情况下从下拉列表中获取部门的值。