2013-08-25 53 views
-1

自動完成功能附加到此輸入字段,id =「search」。當我輸入文本時,什麼都沒有顯示出來,與在另一個文件中的另一個文本字段上使用Jquery UI日曆之前顯示幾次的搜索結果相反。Jquery自動完成未加載

CHROME和Firefox中的Firebug開發人員控制檯顯示沒有錯誤,並顯示「XHR已完成加載」。我不知道哪裏出了問題!請幫忙。

如default.php

<script src="jquery-1.9.1.js"></script> 
<script src="jquery-ui-1.10.3.custom.min.js"></script> 
<script src="myfunctions.js"></script> 
<link rel="stylesheet" type="text/css" href="jquery-ui-1.10.3.custom.min.css"/> 
<link rel="stylesheet" type="text/css" href="main.css"/> 

    <div id="search_container"><input type="text" onkeyup="showHint(this.value)" id="search" placeholder="Search here"/></div> 

myfunctions.js

function showHint(strvalue) 
{ 
    $("#search").autocomplete({ 
     minLength:2, 
    source: "getHint.php?search="+strvalue, 
    select:function(ui) 
       { 
        log(ui.item? 
        window.location.replace(ui.item.link): 
        "Not Found"); 
       } 
    } 
     ).data("ui-autocomplete")._renderItem = function (ul, item) { 
return $("<li></li>") 
     .data("item.autocomplete", item) 
     .append("<a>" + item.label + "</a>") 
     .appendTo(ul); 
}; 
} 

getHint.php

<?php 
require_once 'myfunctions.php'; 
$search=sanitizeString($_GET['search']); 
$query="Select * from students where firstname like '%$search%' or lastname like '%$search% order by firstname'"; 
$result= queryMysql($query); 
$k=0; 
while($row= mysql_fetch_array($result)) 
{ 
    $email=$row['email']; 
    $name=nameOf($email); 
    $studentid=studentidOf($email); 
    $as[]['label']="<a style='text-decoration:none' href='student_profile.php?studentid=$studentid'><div class='search_elements'><span class='search_elements_span'>$name</span></div></a>"; 
    $as[$k++]['value']=$name; 

} 

header('Cache-Control: no-cache, must-revalidate'); 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Content-type: application/json'); 

echo json_encode($as); 

的main.css

#search_container 
{ 
position: relative; 
top:1px; 
left:750px; 
width:250px; 

} 

#search 
{ 
font-family: cursive; 
font-size: 14px; 
color: #999999; 
width:250px; 
position:relative; 
background: white; 
z-index: 11; 
top: 1px; 
} 

#search:focus 
{ 

font-family: cursive; 
font-size: 14px; 
width: 250px; 
color: black; 
} 

瀏覽器中的檢查代碼,輸入文本區域顯示以下後,我搜索項目:

<input id="searchstr" class="ui-autocomplete-input" type="text" placeholder="Search here" name="searchstr" autocomplete="off"></input> 

爲什麼的autocomplete屬性設置爲「關」?

+0

你檢查了AJAX請求的內容嗎?標題200的響應正常並不意味着響應正常。 –

+0

@Mathletics輸入文本區域的ID爲'search' – kamal0808

+0

@dragoste - 是的,我已經在MySQL上手動檢查了所有查詢。此外,自動完成搜索一次正常,我以後沒有對PHP文件進行任何更改! – kamal0808

回答

0

getHint.php需要的文件'myfunctions.php'是打印數據。如果必須以JSON的形式對數組或數據進行編碼,則getHint.php文件不應該打印或「回顯」任何內容。

從'myfunctions.php'中刪除打印數據效果非常好。 可以通過Mozilla Firefox中的FIREBUG應用程序檢查JSON編碼數據。