Form Autocomplete

Asked

Viewed 72 times

1

I’m trying to make an autocomplete form, however so far it doesn’t work, I don’t know if anyone can identify the error

  <div class="form-group">
    <label class="control-label col-sm-4" for="Nome"> Nome </label>
    <div class="col-sm-6"> 
      <input type="text" class="form-control " id="Nome" autocomplete="on"  placeholder="Digite o nome do terceiro" name="Nome">
    </div>
    <span class='msg-erro msg-Nome'></span>
  </div>

<script>
$(document).ready(function(){

 $('#Nome').typeahead({
  source: function(sql, res)
  {
   $.ajax({
    url:"Includes/search.php",
    method:"POST",
    data:{sql:sql},
    dataType:"json",
    success:function(data)
    {
     result($.map(data, function(item){
      return item;
     }));
    }
   })
  }
 });

});
</script>

search php.

<?php

 $request = mysqli_real_escape_string($lig, $_POST["sql"]);
$sql = " SELECT * FROM Terceiros WHERE Nome LIKE '%".$request."%' ";
$res=$lig->query($sql);
$data = array();

if(mysqli_num_rows($res) > 0)
{
 while($lin = mysqli_fetch_assoc($res))
 {
  $data[] = $lin["Nome"];
 }
 echo json_encode($data);
}

?>
No answers

Browser other questions tagged

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