[英]Jquery autocomplete not showing dropdown results
I am using a jquery autocomplete but the suggestions or the dropdown list is not showing up. 我正在使用jquery自动完成功能,但是没有显示建议或下拉列表。
My Javascript is: 我的Javascript是:
$("#product").autocomplete({
source: function(request, response){
$.getJSON('../searchProduct.php', {term: $("#product").val()}, function(data){
alert(data);
}, response());
}
});
and here is my searchProduct.php 这是我的searchProduct.php
$searchTerm = $_GET['term'];
$results = $wpdb->get_results("SELECT * FROM wp_products WHERE productName LIKE '".$searchTerm."%'");
foreach ( $results as $products ) {
$data[] = $products->productName;
}
echo json_encode($data);
When I alert the data, it prints the array (for example, it shows Pebbe,Kristel,Bunoan). 当我提醒数据时,它会打印数组(例如,它显示Pebbe,Kristel,Bunoan)。
Is there something wrong with the $data that I'm passing? 我传递的$ data是否有问题? or is it something else?
或者是别的什么? What could be the problem?
可能是什么问题呢? Please help.
请帮忙。 Thank you.
谢谢。
Use it like this, call response with data in the callback 这样使用,在回调中使用数据调用响应
$("#product").autocomplete({
source: function(request, response){
$.getJSON('../searchProduct.php', {term: $("#product").val()}, function(data){
response(data);
});
}
});
EDIT: you could also use the request passed in source function like this 编辑:您也可以使用在源函数中传递的请求,如下所示
$("#product").autocomplete({
source: function(request, response){
// request === {term: "the value you typed"}
// if response you are not parsing the data received then just pass response to getJSON
$.getJSON('../searchProduct.php', request, response);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.