My autocomplete ignores my JSON data and shows random numbersGenerating random whole numbers in JavaScript in a specific range?Generate random number between two numbers in JavaScriptFormat number to always show 2 decimal placesHow to send FormData objects with Ajax-requests in jQuery?Google Maps Autocomplete Result in Bootstrap Modal DialogJQuery Autocomplete, populate with data from pHp jsonjQueryUI autocomplete JSON not returning expected dataAutocomplete read custom JSON from AJAX responseShow autocomplete suggestions on another eventHow to dynamically update Materialize chips autocomplete data via ajax as I type?

Reducing using/foreach/using nesting with a helper extension

Was I subtly told to resign?

Are neural networks prone to catastrophic forgetting?

Can I play a first turn Simic Growth Chamber to have 3 mana available in the second turn?

Machine learning and operations research projects

Why does the U.S. tolerate foreign influence from Saudi Arabia and Israel on its domestic policies while not tolerating that from China or Russia?

How to say "to make my heart sing"

Why didn't Thanos kill all the Dwarves on Nidavellir?

Is there a word for a message that is intended to be intercepted by an adversary?

Modulus Operandi

How were Martello towers supposed to work?

Why weren't bootable game disks ever common on the IBM PC?

How did the hit man miss?

Received a dinner invitation through my employer's email, is it ok to attend?

Why does my String turn into Integers instead of letters after I add characters with +?

How can I deal with a player trying to insert real-world mythology into my homebrew setting?

Are randomly-generated passwords starting with "a" less secure?

Parse source code of the RAPID robot-automation language

How would vampires avoid contracting diseases?

What is this welding tool I found in my attic?

Is Arc Length always irrational between two rational points?

Is purchasing foreign currency before going abroad a losing proposition?

If your plane is out-of-control, why does military training instruct releasing the joystick to neutralize controls?

How to (graphically) present computational results?



My autocomplete ignores my JSON data and shows random numbers


Generating random whole numbers in JavaScript in a specific range?Generate random number between two numbers in JavaScriptFormat number to always show 2 decimal placesHow to send FormData objects with Ajax-requests in jQuery?Google Maps Autocomplete Result in Bootstrap Modal DialogJQuery Autocomplete, populate with data from pHp jsonjQueryUI autocomplete JSON not returning expected dataAutocomplete read custom JSON from AJAX responseShow autocomplete suggestions on another eventHow to dynamically update Materialize chips autocomplete data via ajax as I type?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm trying to add the autocomplete feature to one of my input-field, as soon as the user types the function triggers and it queries the DB to get the numbers.



This is the input field code



<div class="input-field col s12 m3 offset-m1 l2 offset-l1">
<input id="NumEmpleado" name="NumEmpleado" type="text" class="validate autocomplete" autocomplete="off" required="">
<label for="NumEmpleado">N° de Empleado</label>
</div>


This is the script code:



<script>
$(document).ready(function()
$(document).on('input', 'input.autocomplete', function()
let inputText = $(this).val(); //Gets text from input
$.get('suggest.php?key=' + inputText) //Makes the query
.done(function(suggestions) //gets JSON data as suggestions
console.log(suggestions); //Prints
$('input.autocomplete').autocomplete( //Initialize auto complete with new data
data: suggestions
);
);
);
);
</script>


This is suggest.php - which is triggered when the user types



<?php
$key=$_GET['key'];
$NumEmpleado = array();
$conn = mysqli_connect('localhost', 'root', '', 'unacar');

$query= "select NumEmpleado from academico where NumEmpleado LIKE '%$key%'";
$res = mysqli_query($conn, $query);

if($res->num_rows>0)
while($row = $res->fetch_assoc())
$NumEmpleado[trim($row["NumEmpleado"])] = null;


echo json_encode($NumEmpleado);
flush();
?>


I have noticed this things so far:



When I press space bar on the input field while looking at console, the json data is exactly as the data on the DB
Red box is DB query in Heidi SQL



When I press 1, which should give me the '31' as the only autocomplete option, it shows 2 options and this are not from the JSON data and for some reason, it tries to show a image(src: uknown).



enter image description here



Also tries to load some stuff



enter image description here



If I type 9, it should give me 3 options; 9, 93, and 98



enter image description here
And again, it tries to reach somewhere.



Thank you for reading, have a good day.










share|improve this question




























    1















    I'm trying to add the autocomplete feature to one of my input-field, as soon as the user types the function triggers and it queries the DB to get the numbers.



    This is the input field code



    <div class="input-field col s12 m3 offset-m1 l2 offset-l1">
    <input id="NumEmpleado" name="NumEmpleado" type="text" class="validate autocomplete" autocomplete="off" required="">
    <label for="NumEmpleado">N° de Empleado</label>
    </div>


    This is the script code:



    <script>
    $(document).ready(function()
    $(document).on('input', 'input.autocomplete', function()
    let inputText = $(this).val(); //Gets text from input
    $.get('suggest.php?key=' + inputText) //Makes the query
    .done(function(suggestions) //gets JSON data as suggestions
    console.log(suggestions); //Prints
    $('input.autocomplete').autocomplete( //Initialize auto complete with new data
    data: suggestions
    );
    );
    );
    );
    </script>


    This is suggest.php - which is triggered when the user types



    <?php
    $key=$_GET['key'];
    $NumEmpleado = array();
    $conn = mysqli_connect('localhost', 'root', '', 'unacar');

    $query= "select NumEmpleado from academico where NumEmpleado LIKE '%$key%'";
    $res = mysqli_query($conn, $query);

    if($res->num_rows>0)
    while($row = $res->fetch_assoc())
    $NumEmpleado[trim($row["NumEmpleado"])] = null;


    echo json_encode($NumEmpleado);
    flush();
    ?>


    I have noticed this things so far:



    When I press space bar on the input field while looking at console, the json data is exactly as the data on the DB
    Red box is DB query in Heidi SQL



    When I press 1, which should give me the '31' as the only autocomplete option, it shows 2 options and this are not from the JSON data and for some reason, it tries to show a image(src: uknown).



    enter image description here



    Also tries to load some stuff



    enter image description here



    If I type 9, it should give me 3 options; 9, 93, and 98



    enter image description here
    And again, it tries to reach somewhere.



    Thank you for reading, have a good day.










    share|improve this question
























      1












      1








      1








      I'm trying to add the autocomplete feature to one of my input-field, as soon as the user types the function triggers and it queries the DB to get the numbers.



      This is the input field code



      <div class="input-field col s12 m3 offset-m1 l2 offset-l1">
      <input id="NumEmpleado" name="NumEmpleado" type="text" class="validate autocomplete" autocomplete="off" required="">
      <label for="NumEmpleado">N° de Empleado</label>
      </div>


      This is the script code:



      <script>
      $(document).ready(function()
      $(document).on('input', 'input.autocomplete', function()
      let inputText = $(this).val(); //Gets text from input
      $.get('suggest.php?key=' + inputText) //Makes the query
      .done(function(suggestions) //gets JSON data as suggestions
      console.log(suggestions); //Prints
      $('input.autocomplete').autocomplete( //Initialize auto complete with new data
      data: suggestions
      );
      );
      );
      );
      </script>


      This is suggest.php - which is triggered when the user types



      <?php
      $key=$_GET['key'];
      $NumEmpleado = array();
      $conn = mysqli_connect('localhost', 'root', '', 'unacar');

      $query= "select NumEmpleado from academico where NumEmpleado LIKE '%$key%'";
      $res = mysqli_query($conn, $query);

      if($res->num_rows>0)
      while($row = $res->fetch_assoc())
      $NumEmpleado[trim($row["NumEmpleado"])] = null;


      echo json_encode($NumEmpleado);
      flush();
      ?>


      I have noticed this things so far:



      When I press space bar on the input field while looking at console, the json data is exactly as the data on the DB
      Red box is DB query in Heidi SQL



      When I press 1, which should give me the '31' as the only autocomplete option, it shows 2 options and this are not from the JSON data and for some reason, it tries to show a image(src: uknown).



      enter image description here



      Also tries to load some stuff



      enter image description here



      If I type 9, it should give me 3 options; 9, 93, and 98



      enter image description here
      And again, it tries to reach somewhere.



      Thank you for reading, have a good day.










      share|improve this question














      I'm trying to add the autocomplete feature to one of my input-field, as soon as the user types the function triggers and it queries the DB to get the numbers.



      This is the input field code



      <div class="input-field col s12 m3 offset-m1 l2 offset-l1">
      <input id="NumEmpleado" name="NumEmpleado" type="text" class="validate autocomplete" autocomplete="off" required="">
      <label for="NumEmpleado">N° de Empleado</label>
      </div>


      This is the script code:



      <script>
      $(document).ready(function()
      $(document).on('input', 'input.autocomplete', function()
      let inputText = $(this).val(); //Gets text from input
      $.get('suggest.php?key=' + inputText) //Makes the query
      .done(function(suggestions) //gets JSON data as suggestions
      console.log(suggestions); //Prints
      $('input.autocomplete').autocomplete( //Initialize auto complete with new data
      data: suggestions
      );
      );
      );
      );
      </script>


      This is suggest.php - which is triggered when the user types



      <?php
      $key=$_GET['key'];
      $NumEmpleado = array();
      $conn = mysqli_connect('localhost', 'root', '', 'unacar');

      $query= "select NumEmpleado from academico where NumEmpleado LIKE '%$key%'";
      $res = mysqli_query($conn, $query);

      if($res->num_rows>0)
      while($row = $res->fetch_assoc())
      $NumEmpleado[trim($row["NumEmpleado"])] = null;


      echo json_encode($NumEmpleado);
      flush();
      ?>


      I have noticed this things so far:



      When I press space bar on the input field while looking at console, the json data is exactly as the data on the DB
      Red box is DB query in Heidi SQL



      When I press 1, which should give me the '31' as the only autocomplete option, it shows 2 options and this are not from the JSON data and for some reason, it tries to show a image(src: uknown).



      enter image description here



      Also tries to load some stuff



      enter image description here



      If I type 9, it should give me 3 options; 9, 93, and 98



      enter image description here
      And again, it tries to reach somewhere.



      Thank you for reading, have a good day.







      javascript php mysql materialize






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 3:19









      David SelemDavid Selem

      399 bronze badges




      399 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Jquery autocomplete accept fix key and value (label and value) during initialization. So, first of all, you have to convert your result to the specific key value like below.



           $(document).ready(function()
          $( "#tags" ).autocomplete(
          source: function(request, response)
          $.ajax(
          url: 'suggest.php?key=' + $('#text_box_id').val(),
          dataType: "json",
          type: "GET",
          contentType: "application/json; charset=utf-8",
          success: function (data)
          response($.map(data.d, function (item)
          return
          label: item[0],
          val: item[1]

          ))

          );

          );
          );


          It might help you.






          share|improve this answer

























          • Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

            – David Selem
            Mar 26 at 7:19











          • Please check it again. The answer has been updated.

            – narayansharma91
            Mar 26 at 7:43










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349357%2fmy-autocomplete-ignores-my-json-data-and-shows-random-numbers%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Jquery autocomplete accept fix key and value (label and value) during initialization. So, first of all, you have to convert your result to the specific key value like below.



           $(document).ready(function()
          $( "#tags" ).autocomplete(
          source: function(request, response)
          $.ajax(
          url: 'suggest.php?key=' + $('#text_box_id').val(),
          dataType: "json",
          type: "GET",
          contentType: "application/json; charset=utf-8",
          success: function (data)
          response($.map(data.d, function (item)
          return
          label: item[0],
          val: item[1]

          ))

          );

          );
          );


          It might help you.






          share|improve this answer

























          • Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

            – David Selem
            Mar 26 at 7:19











          • Please check it again. The answer has been updated.

            – narayansharma91
            Mar 26 at 7:43















          0














          Jquery autocomplete accept fix key and value (label and value) during initialization. So, first of all, you have to convert your result to the specific key value like below.



           $(document).ready(function()
          $( "#tags" ).autocomplete(
          source: function(request, response)
          $.ajax(
          url: 'suggest.php?key=' + $('#text_box_id').val(),
          dataType: "json",
          type: "GET",
          contentType: "application/json; charset=utf-8",
          success: function (data)
          response($.map(data.d, function (item)
          return
          label: item[0],
          val: item[1]

          ))

          );

          );
          );


          It might help you.






          share|improve this answer

























          • Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

            – David Selem
            Mar 26 at 7:19











          • Please check it again. The answer has been updated.

            – narayansharma91
            Mar 26 at 7:43













          0












          0








          0







          Jquery autocomplete accept fix key and value (label and value) during initialization. So, first of all, you have to convert your result to the specific key value like below.



           $(document).ready(function()
          $( "#tags" ).autocomplete(
          source: function(request, response)
          $.ajax(
          url: 'suggest.php?key=' + $('#text_box_id').val(),
          dataType: "json",
          type: "GET",
          contentType: "application/json; charset=utf-8",
          success: function (data)
          response($.map(data.d, function (item)
          return
          label: item[0],
          val: item[1]

          ))

          );

          );
          );


          It might help you.






          share|improve this answer















          Jquery autocomplete accept fix key and value (label and value) during initialization. So, first of all, you have to convert your result to the specific key value like below.



           $(document).ready(function()
          $( "#tags" ).autocomplete(
          source: function(request, response)
          $.ajax(
          url: 'suggest.php?key=' + $('#text_box_id').val(),
          dataType: "json",
          type: "GET",
          contentType: "application/json; charset=utf-8",
          success: function (data)
          response($.map(data.d, function (item)
          return
          label: item[0],
          val: item[1]

          ))

          );

          );
          );


          It might help you.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 26 at 7:42

























          answered Mar 26 at 4:39









          narayansharma91narayansharma91

          1,6171 gold badge6 silver badges16 bronze badges




          1,6171 gold badge6 silver badges16 bronze badges












          • Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

            – David Selem
            Mar 26 at 7:19











          • Please check it again. The answer has been updated.

            – narayansharma91
            Mar 26 at 7:43

















          • Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

            – David Selem
            Mar 26 at 7:19











          • Please check it again. The answer has been updated.

            – narayansharma91
            Mar 26 at 7:43
















          Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

          – David Selem
          Mar 26 at 7:19





          Thanks for your reply, your code is giving me an error syntax i.imgur.com/tcj4C3d.png

          – David Selem
          Mar 26 at 7:19













          Please check it again. The answer has been updated.

          – narayansharma91
          Mar 26 at 7:43





          Please check it again. The answer has been updated.

          – narayansharma91
          Mar 26 at 7:43








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349357%2fmy-autocomplete-ignores-my-json-data-and-shows-random-numbers%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해