编辑:第一篇文章现在包含工作代码,并已将问题编辑出来。
我正在制作一个从 SQL 查询填充 DDL 的网页。选择后,它会执行第二个 SQL 查询以填充第二个 DDL。脚本正在触发并且没有引发错误,但没有填充第二个 DDL。
我的代码
<Head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>$(function() {
$("#exchangenameselect").change(function() {
$("#jobnoselect").load("getter.php?choice=" + $("#exchangenameselect").val());
});
});
</Script>
</Head>
<body>
<!-- Perex -->
<div id="perex" class="box">
<?php $conn = mysqli_connect('host', 'user', 'pass', 'database')
or die ('Cannot connect to db');?>
Exchange:
<p><select id="exchangenameselect">
<option>Choose</option>
<?php
$result = $conn->query("select distinct Exchange from MasterJobTable");
while ($row = $result->fetch_assoc()) {
unset($exchange);
$exchange = $row['Exchange'];
echo '<option>'.$exchange.'</option>';
echo "\r\n";
}
?>
</select></p>
Job Number:
<p><select id="jobnoselect">
<option>Choose</option>
</select></p>
</div> <!-- /perex -->
</body>
getter.php 中的代码是
<?php
$username = "user";
$password = "passs";
$hostname = "host";
$dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$selected = mysql_select_db("database", $dbhandle) or die("Could not select examples");
$choice = mysql_real_escape_string($_GET['choice']);
$query = "SELECT * FROM MasterJobTable WHERE Exchange='$choice'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "<option>" . $row['JobNo'] . "</option>";
}
?>
Getter.php 正在返回数据,而 jQuery 正在做一些事情,这可以在站点http://btstats.000webhost.com/index2.html上看到,并且可以在http://btstats.host22.com/上直接访问 getter getter.php?=约克
有没有人可以解释为什么这不起作用?