我希望有人可以帮助我确定我在使用以下 jquery Ajax 代码时遇到的问题。当从下拉列表中选择职员时,下面的 php 文件正在调用 Select 语句。在输入列表中应该出现工作人员的薪水。不幸的是,什么也没有发生。
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<title>AJAX und PHP ganz einfach!</title>
<script>
$(document).ready(function() {
$('.id').change(function() {
$.ajax({
type: 'GET',
url: 'anzeige.php',
data: 'id=' +$('.id').val(),
success: function(msg) {
$('#ajaxAusgabe').html(msg);
}
});
});
}); //document.ready
</script>
<?php
$link = mysql_connect("localhost","sandrag","bubblekey13","staffbridgetest");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("staffbridgetest", $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>
</head>
<p>Bitte waehlen Sie einen Mitarbeiter:</p>
<form>
<select name="id">
<option value=""></option>
<?php
$query = mysql_query("SELECT Mitarbeiternummer, Vorname, Nachname FROM mitarbeiter where mitarbeiternummer>0 order by nachname");
while ($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['Mitarbeiternummer'].'">'.$row['Nachname'].', '.$row['Vorname'].'</option>';
}
echo'</select>';
?>
<div id="ajaxAusgabe"></div>
</form>
</script>
</body>
</html>
这通过 Select 语句连接到另一个 php 文件:
<?php
$link = mysql_connect("localhost","sandrag","bubblekey13","staffbridgetest");
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("staffbridgetest", $link);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$staffid=$_GET['id'];
$sql = "SELECT Stundenlohn from gehalt where mitarbeiternummer='$staffid' limit 1";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['Stundenlohn'];
}
?>
我真的不知道为什么它不起作用。