Bonjour à tous,
Je souhaite utiliser l'autocomplete de jQuery.
Depuis qq heures, malgré un ratissage intensif du Web, je galère pour faire fonctionner le template remote datasource de Autocomplete Widget.
Mon html :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en"> <head> <meta charset="utf-8" /> <title>jQuery UI Autocomplete - Remote datasource</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> <link rel="stylesheet" href="FS/demo.css" /> <style> .ui-autocomplete-loading { background: white url('Images/ajax-loader-EIP-2.gif') right center no-repeat; } </style> <script> $(function() { function log( message ) { $( "<div>" ).text( message ).prependTo( "#log" ); $( "#log" ).scrollTop( 0 ); } $( "#birds" ).autocomplete({ source: "searchAutoComplete.php", minLength: 4, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.value + " aka " : "Nothing selected, input was " + this.value ); }, }); }); </script> </head> <body> <div class="ui-widget"> <label for="birds">Birds: </label> <input name="" type="text" id="birds" /> </div> <div class="ui-widget" style="margin-top: 2em; font-family: Arial;"> Result: <div id="log" style="height: 200px; width: 300px; overflow: auto;" class="ui-widget-content"></div> </div> </body> </html>
mon PHP searchAutoComplete.php :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <?php include("Param/Connexion.php"); $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $sql = "SELECT Email as value FROM Comp_init WHERE Email LIKE '".$term."%'"; $result = mysql_query($sql);//query the database for entries containing the term while ($row = mysql_fetch_assoc($result))//loop through the retrieved values { $row['value']=htmlentities(stripslashes($row['value'])); $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data ?>
le json retourné est de la forme :
Pourquoi ce script de fonctionne-t-il pas sachant qu'il n'y a pas de retour dans
Code : Sélectionner tout - Visualiser dans une fenêtre à part [{"value":"aaaaaa@free.fr"}]
Code html : Sélectionner tout - Visualiser dans une fenêtre à part <div class="ui-widget" style="margin-top: 2em; font-family: Arial;">
Si qqu'un a une explication ... d'avance merci
Partager