1
Using the Jquery Ui autocomplete I have had a small problem. I am performing an ajax search to feed a text field. In this field a discipline will be sought and the autocomplete assembles the auto-suggestion menu.
The search and presentation of the data works correctly. The problem is the autocomplete does the search once or does not update the data refinement when one or more characters are added for example:
Ex.: if I do the BAN search I am presented DATABASE and KANBAN as results. If I add one more character and form BANO, the suggestion menu is not hidden (since no given one was found). If I add one more character and form BANC the KANBAN option is not hidden
In short, in the third character the search is done, however, when a new character is added the auto-suggestion menu is not updated.
I have the following code:
HTML
<input type="text" id="nm">
JQUERY
$("#nm").autocomplete({
minLength:3,
source: function(request,response){
$.post({
url:'getDisciplina.php',
dataType:'json',
data:{'term':request.term},
}).done(function(data){
response($.map(data,function(item){
return({
label: item.label,
value: item.label,
id: item.value,
});
}));
});
},
getDisciplina.php
public function getDisciplina(){
$data = (isset($_POST['term']))?$_POST['term']:false;
$model = new DisciplinaModel;
$rs = $model->getDisciplina($data);
$arr = [];
if($rs){
foreach ($rs as $r){
array_push($arr,["label"=>$r->descr,"value"=>$r->descr,"id"=>$r->id]);
}
print_r(json_encode($arr));
}
else{
print_r(false);
}
//Retorna algo como:[{"label":"Banco de Dados I","value":"2"},{"label":"Kanban","value":"3"}]
Your problem is not in jquery, but in the like of the bank that is wrong, it would be nice to put the query to facilitate.
– Otto
The query was correct, there was nothing wrong with it, it was a problem in the false php stream that was not being passed in json format
– Rúbio Falcão