Jquery php自动完成列表未根据输入进行过滤
我有一个输入框,我正在使用 Jquery 自动完成功能。当我在输入框中键入内容时,列表会正确显示,其中包含前 16 个“值”。当我单击其中一个值时,输入框会填充该值。所以,到目前为止一切都还好。我的问题如下。该列表没有根据我的输入进行过滤。该列表保持静态。我不明白为什么。希望有人能帮忙。预先感谢您的回复。干杯。马克.
我的 HTML:
<input type="text" id="moi"/>
我的 PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
require("../inc/connect.inc.php");
mysql_set_charset('utf8');
$result = mysql_query("SELECT * FROM search_loc_test");
$row=mysql_fetch_assoc($result);
$return = array();
while($row=mysql_fetch_assoc($result)){
array_push($return,array('label'=>$row['seaerch_loc'],'value'=>$row['seaerch_loc']));}
echo(json_encode($return));
?>
我的 JS:
$( "#moi" ).autocomplete({
source: "php/search_loc.php",
minLength: 2
});
I have an input box for which I am using the Jquery autocomplete function. When I type in the input box, the list appears correctly with the 16 first "values". When I click on one of the values, the input box is populated with that value. So, so far everything ok. My problem is as follows. The list is not filtered according to my input. The list stays static. I do not understand why. Hope someone can help. Thank you in advance for your replies. Cheers. Marc.
My HTML:
<input type="text" id="moi"/>
My PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
require("../inc/connect.inc.php");
mysql_set_charset('utf8');
$result = mysql_query("SELECT * FROM search_loc_test");
$row=mysql_fetch_assoc($result);
$return = array();
while($row=mysql_fetch_assoc($result)){
array_push($return,array('label'=>$row['seaerch_loc'],'value'=>$row['seaerch_loc']));}
echo(json_encode($return));
?>
My JS:
$( "#moi" ).autocomplete({
source: "php/search_loc.php",
minLength: 2
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要更新 SQL 查询以处理自动完成发送的
term
。当您的源被调用(通过 GET)时,它将被如下调用:
php/search_loc.php?term=bb
因此,在您的 PHP 脚本中,您需要获取搜索词并使用它来过滤来自数据库的结果...类似于:
Docs喜欢这里
You need to update your SQL query to process the
term
sent by the autocomplete.When your source is called (via GET) it will be called as follows :
php/search_loc.php?term=bb
So in your PHP script you need to take the search term and use it to filter the results from the DB ... Something like :
Docs for LIKE here