Error with jquery UI Autocomplete

Asked

Viewed 72 times

0

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

Imagem do erro:

PHP: (I used as an example, because I didn’t add like in select, these are dynamic values!

    <?php

 require_once('acessabanco.php');

 $objDb = new db();
 $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
  });

You’re making my mistake again.. NOTE: If I use the example of the jquery site itself, it works normally, but when I search the database it shows me this..

If anyone knows what this is about, I’d be very grateful!

1 answer

0


Put the:

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

Within the function that loads the JSON:

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

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

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

Putting out, the variable var teste shall not be recognised as it has not yet been defined in .autocomplete.

  • It worked!! Thank you so much for your help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.