Bonjour à tous,
Je viens vers vous avec un souci dont je n'arrive pas à me sortir depuis quelques heures.
Je cherche à mettre en place le widget autocomplete standard de jQuery.
Visiblement le script se lance bien, mais il n'affiche aucun résultat en retour.
Mon code 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
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Remote with caching</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/Style.css" />
  <style>
  .ui-autocomplete-loading {
    background: white url('Images/ajax-Petit-loader.gif') right center no-repeat;
  }
  </style>
  <script>
...
  </script>
</head>
<body>
<div class="ui-widget">
	<label for="birds">Birds: </label>
  <input id="birds" />
</div>
</body>
</html>
Code : 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
  $(function() {
    var cache = {};
    $( "#birds" ).autocomplete({
      minLength: 4,
      source: function( request, response ) {
        var term = request.term;
        if ( term in cache ) {
          response( cache[ term ] );
          return;
        }
 
        $.getJSON( "PHP/rechercheEmail.php", request, function( data, status, xhr ) {
          cache[ term ] = data;
          response( data );
        });
      }
    });
  });
Le code PHP du fichier de recherche :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
<?php
include("../XXXX/Connexion.php");
$search = protect($_GET['term']);
$result = mysql_query("SELECT Email FROM Essai1 WHERE Email LIKE '$search%' ORDER BY Email ASC") or die('Erreur de process');
$json = array();
$first = true;
while ($row = mysql_fetch_assoc($result)) {
	array_push($json, "{'value':'".$row['Email']."'}");
}
echo json_encode($json);
?>

Si quelqu'un peut me dire pourquoi ce script ne fonctionne pas jusqu'au bout, d'avance merci