2015-07-09 60 views
1

我試圖讓我的公司爲我建立的網站工作自動完成,但我似乎無法獲得執行的jQuery功能。該網站建立在Wordpress之上。通過PHP錯誤jQuery自動完成

輸入線:

<strong>Customer: </strong> <input type='text' name='cust' id='cust'> 

自動完成:

<script type='text/javascript'> 
jQuery('#cust').autocomplete({ 
    source : "Scripts/cust_search.php", 
    minLength:1 
}); 

而且cust_search.php:

<? 
$term = trim(strip_tags($_GET[ "term" ])); 

$a_json = array(); 
$a_json_row = array(); 

if ($companies = $panther->get_results("SELECT Cust_ID, Cust_Name FROM Customer LIKE '%$term%' ORDER BY Cust_Name ASC;")) { 
while ($row = mysqli_fetch_array($companies)) { 
    $a_json_row ["id"]=$panther->escape($row['Cust_ID']); 
    $a_json_row ["value"]=$panther->escape($row['Cust_Name']); 
    $a_json_row ["label"]=$panther->escape($row['Cust_Name']); 

    array_push($a_json, $a_json_row); 
} 
} 

echo json_encode($a_json); 
?> 
+0

你看了在瀏覽器的控制檯中的請求/響應? –

回答

0

這似乎是你的SQL查詢的問題。 你缺少WHERE語句

嘗試

"SELECT Cust_ID, Cust_Name FROM Customer WHERE **Cust_Name** LIKE '%$term%' ORDER BY Cust_Name ASC;" 

代替:

"SELECT Cust_ID, Cust_Name FROM Customer LIKE '%$term%' ORDER BY Cust_Name ASC;" 
+0

非常感謝您接受這一點,但我無法達到php文件是問題的地步。我需要檢查腳本請求發生​​了什麼,因爲.autocomplete在控制檯中不被視爲有效的功能。 –

+0

請發佈您的控制檯中顯示的錯誤。 – leocoder

+0

請發佈顯示在控制檯中的錯誤。 如果自動完成不是一個有效的函數可能是你的自動完成整合到jQuery作爲插件, 似乎自動完成它沒有被定義爲jQuery。 試試:這個 1.-進口你的jQuery庫文件 2.-導入你的自動完成庫文件 3.-試試$('#element')。autocomplete(options); – leocoder