autocomplete jQuery display data
I'm learning jQuery and i would like to use autocomplete. But i don't know
why my data don't display in my html. Can you explain me what's wrong in
this source code please.
<?php
// receive data
if(isset($_GET['q'])) {
$q = addslashes(htmlspecialchars($_GET['q'])); // protection
require_once('../required.php');
//our request
$rslt= $pdoSearch->findCity($q);
$tab=array();
foreach ($rslt as $data){
array_push($tab,
array(
"label" => $data['fistname']." ".$data['lastname']."
".$data['login']." ".$data['mdp']." ".$data['city'],
"value" => $data['id']
)
);
}
echo json_encode($tab);
} ?>
My autocomplete file :
$(function(){
$('#search').autocomplete({
source: 'fichier.php',
select: function (event, ui) {
$("#search").val(ui.item.label);
$("#id").val(ui.item.value);
}
});
$('#button').click(function() {
$("#id").val();
});
});
And my HTML file :
<fieldset id="field" >
<legend>Fonctionnalités</legend><br />
<form class="icon" method="get">
<label for="search">Recherche: </label>
<input id="id" name="id" hidden="hidden" />
<input type="text" id="search" style="width: 600px;"/>
<input type="submit" id="button"/>
</form>
</fieldset>
Thanks in advance for your help. Best regards,
No comments:
Post a Comment