2015-07-09 97 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