我是ajax新手,在设置刷新按钮时,我在实现动态重新加载组合框时遇到了麻烦。
<html>
<head>
<script type="text/javascript">
$(function() {
alert('Document is ready');
$('#b').on('click', function(){
alert('You clicked the button');
$('#s').load(test.php);
});
});
</script>
</head>
<body>
<select name="s" id="s">
<?php $server = 'localhost'; //localhost is the usual name of the server if apache/Linux.
$login = 'root';
$pword = '';
$dbname = 'item';
mysql_connect($server,$login,$pword) or die($connect_error); //or die(mysql_error());
mysql_select_db($dbname) or die($connect_error);
?>
<?php
$query = "select * from ajax_categories";
$results = mysql_query($query);
while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option>
<?php
}?>
</select>
<input type = "button" value="go" name="b" id="b">
和test.php代码:
<?php
$query = "select * from ajax_categories";
$results = mysql_query($query);
while ($rows = mysql_fetch_assoc(@$results))
{?>
<option value="<?php echo $rows['id'];?>"><?php echo $rows['category'];?></option>
<?php
}?>
显示警告,但是组合框没有重新加载新的数据库内容
试着改变这个:
$('#s').load(test.php);
to this:
$('#s').load('test.php');