autocomplete avec source php
Bonjour,
Je découvre Jquery et l'autocomplete en particulier.
Lorsque mes données sont en "interne", pas de soucis.
Si je fais appel à une source php, l'évènement ne fonctionne pas.
Voici mon code 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
|
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/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.2/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script type="text/javascript">
jQuery(document).ready(function($){
$('#rech').autocomplete({source:'getautocomplete.php', minLength:2});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Client :
</label>
<input id="rech" />
</div>
</body>
</html> |
et la source php :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?php
include ("./include/mes_fonctions.php");
open_db();
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM tiers where tie_nom like '%".$term."%' order by tie_nom ");
if ( ! $query )
die ('mysql_query error SELECT tiers' . mysql_error());
$json=array();
while($student=mysql_fetch_array($query))
{
$json[]=array(
'value'=> $student["tie_nom"],
'label'=>$student["tie_nom"]
);
}
echo json_encode($json);
?> |
Merci pour votre aide.