这是我的 index.php,它首先在单击进行排序时起作用
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(function() {
$("#tablesorter-demo").trigger("update");
$("#tablesorter-demo").tablesorter({
sortList: [
[0, 0],
[2, 1]
],
widgets: ['zebra']
});
$("#options").tablesorter({
sortList: [
[0, 0]
],
headers: {
3: {
sorter: false
},
4: {
sorter: false
}
}
});
});
function showUser(str) {
if (str == "") {
document.getElementById("subjtable").innerHTML = "";
return;
}
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("subjtable").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", "getSubject.php?q=" + str, true);
xmlhttp.send();
}
</script>
<title>Faculty Subject</title>
</head>
<body>
<form>
<h1 align="center">Faculty Subject Offerings</h1>
<br/>
<h1>Faculty</h1>
<h1>
<select name="typeselector" onchange="showUser(this.value)">
<option value="Arts">Arts</option>
<option value="Science">Science</option>
</select>
</h1>
<div id="subjtable">
<table id="tablesorter-demo" class="tablesorter" border="1" cellpadding="0" cellspacing="1">
<thead>
<tr>
<th>Subject Code</th>
<th>Subject Title</th>
<th>Lecturer</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php
$mysqli = new mysqli( 'localhost', 'root', '9876543210', 'jye');
$stmt = $mysqli->prepare("select subjectcode,title,lecturer,description from erehwonsubjects");
$stmt->execute();
$stmt->bind_result($subjcode,$subjtitle,$lecturer,$description);
while($stmt->fetch()) {
echo <<<TABLE
<tr>
<td>$subjcode</td>
<td>$subjtitle</td>
<td>$lecturer</td>
<td>$description</td>
</tr>
TABLE;
} ?>
</tbody>
</table>
</div>
</form>
</body>
它在运行这个 php 并连接到我的数据库时工作。再提一下。在这个 php 中完美运行
但后来我改变了我的选择框值,它会将方法 POST 发送到另一个 php namegetSubject.php
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript" src="jquery-latest.js"></script>
<script type="text/javascript" src="jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(function() {
$("#tablesorter-demo").trigger("update");
$("#tablesorter-demo").tablesorter({
sortList: [
[0, 0],
[2, 1]
],
widgets: ['zebra']
});
$("#options").tablesorter({
sortList: [
[0, 0]
],
headers: {
3: {
sorter: false
},
4: {
sorter: false
}
}
});
});
</script>
</head>
<body>
<div id="subjtable">
<table id="tablesorter-demo" class="tablesorter" border="1" cellpadding="0" cellspacing="1">
<thead>
<tr>
<th>Subject Code</th>
<th>Subject Title</th>
<th>Lecturer</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<?php $q=$ _GET[ "q"]; $mysqli=n ew mysqli( 'localhost', 'root', '9876543210', 'jye'); $stmt=$ mysqli->prepare("select subjectcode,title,lecturer,description from erehwonsubjects where course = '".$q."'"); $stmt->execute(); $stmt->bind_result($subjcode,$subjtitle,$lecturer,$description); while($stmt->fetch()) { echo
<<<TABLE <tr>
<td>$subjcode</td>
<td>$subjtitle</td>
<td>$lecturer</td>
<td>$description</td>
</tr>TABLE; } ?></tbody>
</table>
</div>
</body>
</html>
然后在第二个 php 那里。我的 Jquery 排序已经无法工作。我的 Jquery 是基于这个网站 http://tablesorter.com/docs/
任何答案将不胜感激。第一次在这里的用户我已经在这里搜索了答案,但对我一无所获