我想創建一個jQuery腳本,這將允許我實現livesearch。到目前爲止,我在屏幕上的所有內容都沒有,沒有任何顯示,我不知道什麼是錯的。有任何想法嗎?JQuery與PHP的livesearch
的javascript:
function searchMembers() {
document.body.style.cursor = "wait";
var gradeMenu = document.getElementById("grade");
var gradeValue = gradeMenu.options[gradeMenu.selectedIndex].text;
var firstNameValue = document.getElementById("firstName").value;
var lastNameValue = document.getElementById("lastName").value;
var studentIDValue = document.getElementById("studentID").value;
$.post (
"search.php",
{'firstName':firstNameValue, 'lastName':lastNameValue, 'grade':gradeValue, 'stID':studentIDValue},
function(data) {
document.getElementById("searchOutput").innerHTML=data;
document.body.style.cursor="auto";
}
);
}
$(document).ready(function() {
var loc = (String)(window.location);
if(loc.indexOf("view_membersWithSearch.php") > 0)
searchMembers();
});
的search.php:
if(isset($_POST['firstName'])) {
$firstNameValue = $_POST['firstName'];
}
if(isset($_POST['lastName'])) {
$lastNameValue - $_POST['lastName'];
}
if(isset($_POST['grade'])) {
$gradeValue = $_POST['grade'];
}
if(isset($_POST['stID'])) {
$studentIDValue = $_POST['stID'];
}
view_membersWithSearch.php:
<div id="searchOutput"></div>
編輯:jQuery是包括在內,我把它放在view_membersWithSearch的底部。 PHP。問題出在我點擊一個菜單或插入文本來更新搜索之後,沒有任何反應。結果應該放置的區域是空白的。默認情況下,我也應該默認顯示所有結果,但也是空白。
編輯2:Firebug給出了這個:HTML文檔的字符編碼沒有被聲明。如果文檔包含US-ASCII範圍之外的字符,則該文檔將在某些瀏覽器配置中呈現亂碼文本。頁面的字符編碼必須在文檔或傳輸協議中聲明。
@MihaiIorga - 也許這是不工作,因爲不包括jQuery的?我們沒有足夠的錯誤信息。 – Aiias 2013-03-23 08:08:35
已經檢查了可能的錯誤螢火蟲..? – 2013-03-23 08:09:37
http://stackoverflow.com/questions/4279282/set-http-header-to-utf-8-php – 2013-03-23 08:17:23