我正在尝试用基于用户ID的mysql数据填充表。当我使用少量用户ID作为选项时,它可以工作。但是,如果我使用并输入用户ID,它会显示包含数秒的表格并将其关闭。
<html>
<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","../action/subs/getcalls.php/?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="788">user 788</option>
<option value="786">User 786</option>
<option value="787">User 787</option>
<option value="789">User 789</option>
</select>
</form>
<br>
<div id="txtHint"><b></b></div>
</body>
</html>
**如果我更换
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="788">user 788</option>
<option value="786">User 786</option>
<option value="787">User 787</option>
<option value="789">User 789</option>
</select>
</form>
通过
<form>
<input name="users" onchange="showUser(this.value)"/>
</form>
该表格将显示几秒钟并关闭
这里是getcall.php
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
include '../db/connect.php';
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM oz2ts_call_logs WHERE member_id = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>Device ID</th>
<th>Title</th>
<th>Note</th>
<th>Status</th>
<th>Case Number</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['device_id'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>" . $row['case_number'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
答案 0 :(得分:0)
“守则”对我有用,只有在您点击“输入”时才会应用onchange,或许您只想将<input name="users" onchange="showUser(this.value)"/>
更改为<input name="users" onkeyup="showUser(this.value)"/>
同样<script src="http://code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
属于头