Aucune liste sur le widget d'autocompletion
Salut à tous
Je pête un plomb sur le widget UI d'autocompletion.
Je cherche juste à récupérer une id et une description d'une requete SQL toute simple.
Merci de m'aider avec un semblant d'explication si possible car je suis perdu sur la théorie de ce widget...
Voici les 2 scripts
le html
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#client" ).autocomplete({
source: "options.php",
datatype: 'json',
select: function( event, ui ) {
$( "#id" ).val( ui.item.value );
}
});
});
</script>
</head>
<body>
<div>
<label for="client">Client</label>
<input id="client">
<input id="id" type="hidden">
</div>
</body>
</html> |
et le fichier PHP de la requête à venir
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| <?php
header("Content-Type: text/xml;charset=utf-8");
$arr = array(
array("client"=> "Caterpillar", "id" => 1 ),
array("client"=> "Schneider", "id" => 2 ),
array("client"=> "Leclerc", "id" => 3),
array("client"=> "Savoie", "id" => 3)
);
echo json_encode($arr);
?> |