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;
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
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).

Also tries to load some stuff

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

And again, it tries to reach somewhere.
Thank you for reading, have a good day.
javascript php mysql materialize
add a comment |
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
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).

Also tries to load some stuff

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

And again, it tries to reach somewhere.
Thank you for reading, have a good day.
javascript php mysql materialize
add a comment |
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
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).

Also tries to load some stuff

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

And again, it tries to reach somewhere.
Thank you for reading, have a good day.
javascript php mysql materialize
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
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).

Also tries to load some stuff

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

And again, it tries to reach somewhere.
Thank you for reading, have a good day.
javascript php mysql materialize
javascript php mysql materialize
asked Mar 26 at 3:19
David SelemDavid Selem
399 bronze badges
399 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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