Autocomplete of jQuery does not suggest results

0

I am assigning the "autocomplete" function of jQuery to an input but it does not show the results.

The data is collected from the BD through a PHP function using the post method. Going through the trace I verified that the data is received, converted into an array of strings and passed to a variable, which is called in the source of the autocomplete function.

I pass the jQuery code:

$.post("../../events_front_end/autocomplete_events/",{'autocomplete':true},function(data,status){
//console.log(data);
var json=JSON.parse(data);
var name_events=json.band_name;

//AQUI ENTRA
console.log(name_events);

var suggestions =new Array();

for (var i =0; i<name_events.length; i++){
  suggestions.push(name_events[i].band_name);
}//end of for

//AQUI ENTRA
console.log(suggestions);

$("#keyword").autocomplete({
  source: suggestions,
  minLength:1,
  select:function(event, ui){
    //AQUI NO ENTRA
    console.log("Estoy en select");
    var keyword =ui.item.label;
    count_event(keyword);
  }
});
}).fail(function(xhr){
  $("#results").load("../../events_front_end/view_error_false/",{'view_error':false});
  $('.pagination').html('');
reset();
});//End of $.post autocomplete

Could someone guide me about where the error might be? I have made several tests without success. Thanks in advance.

    
asked by Sergio Bertomeu 05.12.2016 в 17:01
source

1 answer

-1
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  <script src="https://code.jquery.com/ui/1.11.2/jquery-ui.min.js"></script>
  <link rel="stylesheet" href="https://code.jquery.com/ui/1.11.2/themes/black-tie/jquery-ui.css" />

var suggestions =new Array();
$.post("../../events_front_end/autocomplete_events/",
          {
            'autocomplete':true
          },
          function(data,status){
          var json=JSON.parse(data);
          var name_events=json.band_name;

         //AQUI ENTRA
         console.log(name_events);

         for (var i =0; i<name_events.length; i++)
             {
               suggestions.push(name_events[i].band_name);
             }//end of for    
         }).fail(function(xhr){
               $("#results").load("../../events_front_end/view_error_false/",                         {'view_error':false});
               $('.pagination').html('');
               reset();
    });//End of $.post autocomplete

$("#keyword").autocomplete({
  source: suggestions,
  minLength:1,
  select:function(event, ui){
    //AQUI NO ENTRA
    console.log("Estoy en select");
    var keyword =ui.item.label;
    count_event(keyword);
  }
});
    
answered by 06.12.2016 в 04:05