Having issue with Jquery UI autocomplete
My php code looks like that
if (isset($_REQUEST['term']))
{
$term = trim(strip_tags($_REQUEST['term']));//retrieve the search term that autocomplete sends
$result = $db->query("SELECT company as value,id FROM main WHERE company LIKE '$term'") or die(mysqli_error());;
$results = array();
while ($row = $result->fetch_row()) $results[] = array( 'id' => $row[0] , 'label' => $row[1], 'value' => $row[1] );
echo json_encode($results);
}
Js code below
$("#auto").autocomplete({
source: "index.php",
minLength: 2,//search after two characters
select: function(event,ui){
}
});
And HTML markup
<inpu开发者_如何学运维t id="auto" name="company"/>
What's wrong with the code? It doesn't generate autocomplete option.. No error in php log file. How to fix that problem?
assuming json is ok then you are not doing anything with data you get back
select: function(event,ui){
// do something with the data you get back
//you would usually have a function here to do something with data
// but this sample should be enough for you
var id = ui.id; // id you got back assign to var
var label = ui.label; // label you got back assign to var
$('#gothisback').val(ui.id); //push it to a div
}
精彩评论