I am using jQuery to do an autocomplete and when I click 1 item on the list the input gets all the items of the list(even the < li >..< /li >)
This is the script which I call
if($_GET['q']) {
$queryString = $db->real_escape_string($_GET['q']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM .... WHERE name LIKE '%$queryString%'");
if($query) {
while ($result = $query ->fetch_object()) {
echo "<li>$result->name</li>";
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
// Dont do anything.
} // There is a queryString.
} else {
echo 'There should be no direct access to this script!';
}
And this is the jQuery
<script type="text/javascript">
$(function() {
$("#ac3").autocomplete({
url:'searchcond.php',
select: function(event, ui) {
console.dir(ui);
event.preventDefault();
$("#ac3").text(ui.item.label);
}
});
});
</script>
Also when I type something it does not get it. I have to type it fast to get the correct query
I remember that jquery autocomplete wants just a list of key|values (one per line) response and not an UL-LI list:
EG:
echo “$key|$value\n”;