Error with AutoComplete jquery UI

0

Good afternoon, I'm getting an error that I've never seen, trying to use the jquery autocomplete, follows the image, and the encoding:

PHP:(Iusedasanexample,Ididnotaddthelikeinselect,theyaredynamicvalues!)

<?phprequire_once('acessabanco.php');$objDb=newdb();$link=$objDb->conecta_banco();$sql="SELECT p.sequencia codigo,
                p.nome_completo nome, 
                c.data_nascimento data, 
                t.celular_1 celular
           FROM pessoas p, 
                clientes c, 
                telefones t 
          WHERE p.sequencia = t.cod_pessoa 
            AND c.cod_pessoa = p.sequencia";
 $exec = mysqli_query($link, $sql);     
 if ($exec){
    while ($clientes = mysqli_fetch_array($exec)){
        $vetor[] = array('Sequencia' => $clientes['codigo'], 'Nome' => $clientes['nome']);
    }
    echo json_encode($vetor);
}

JQUERY:

 $.getJSON("php/lista_clientes.php", function(data){
    var teste = [];
    $(data).each(function(key, value){

        teste.push(value.Nome);
    });
});

  $( "#buscar_cliente" ).autocomplete({
    source: teste
  });

If someone knows what it's about, I'll be very grateful if you can help!

    
asked by anonymous 09.12.2017 / 19:46

1 answer

0

Place the:

$( "#buscar_cliente" ).autocomplete({
   source: teste
});

Inside the function that loads JSON:

$.getJSON("conecta.php", function(data){
   var teste = [];
   $(data).each(function(key, value){

      teste.push(value.Nome);
   });

   $( "#buscar_cliente" ).autocomplete({
      source: teste
   });
});

Placing out, the variable var teste will not be recognized because it has not yet been defined in .autocomplete .

    
09.12.2017 / 20:22