0

I am trying to implement Jquery Autocomplete. I'm using the tutorial example from their site but so far it is returning all of my results regardless of what I enter for the search

 <script>
 $(function() {
 $( "#birds" ).autocomplete({
   source: "fetchData.php",
   minLength: 2,
   select: function( event, ui ) {
     log( "Selected: " + ui.item.value + " aka " + ui.item.id );
   }
 });
});

fetchData.php

$conn = new PDO ('odbc:xxx','xxxx','xxxxxx');
$qry = "select distinct name_customer from v_customer_master";
$sql = $conn->query($qry);

//$custName = array();
while($row = $sql->fetch((PDO::FETCH_ASSOC))){
    $row['name_customer'] = mb_convert_encoding($row['name_customer'], 'UTF-8', 'UTF-8');
    $custName[] = $row['name_customer'];
    //array_push($custName,$row['name_customer']);
}

echo json_encode($custName);
SkylarP
  • 39
  • 1
  • 8
  • "When a string is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must support CORS). **The Autocomplete plugin does not filter the results**, instead a query string is added with a term field, which the server-side script should use for filtering the results. For example, if the source option is set to `https://example.com` and the user types `foo`, a GET request would be made to `https://example.com?term=foo`. The data itself can be in the same format as the local data described above." – Twisty Sep 27 '22 at 15:01
  • @Twisty Hi, thank you for your response.I took my example from the AC documentation page (https://jqueryui.com/autocomplete/#remote) and copied their examples to mine and it still doesn't work. my source is returning JSON data. I understand that AC does not filter the results. I've tried adding a query string with the term from a GET request (see below answer). as it stands, this is still not working. – SkylarP Sep 27 '22 at 15:45

1 Answers1

0

I ended up finding a different solution using bootstrap. I copied a tutorial here after tailoring it to my needs I was able to get the typeahead/autocomplete I was looking for.

SkylarP
  • 39
  • 1
  • 8