Jquery autocomplete soucis.
Bonjour
Je viens de passer un bon moment et je n'arrive pas à m'en sortir.
Mon autocomplete basé sur ma base de données ne retourne rien.
Mon fichier test.php
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| <!DOCTYPE html>
<html>
<head>
<title>Titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- JQUERY UI JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<!-- JQUERY UI CSS -->
<link rel="stylesheet" href="themes/jquery-ui.min.css">
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#piece").autocomplete({
source : "rechpieceri.php"
});
});
</script>
</head>
<body>
<div class="ui-widget">
<input type="text" id="piece">
</div>
</body>
</html> |
Mon fichier rechpieceri.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <?php
error_reporting(E_ALL);
include_once("fonction.php");
$term = $_GET['term'];
$cnx = connexion_DBMYSQL($GLOBALS['MYSQLBASE']);
$sql = "select PIE_ID,PIE_LIB from pieces where PIE_LIB like '%".$term ."%'";
$array = array();
$result = requete_SQLMYSQL($sql,$cnx);
while($data = mysql_fetch_assoc($result))
{
array_push($array, utf8_encode(utf8_decode($data["PIE_LIB"])));
//echo utf8_encode(odbc_result($result,utf8_decode("Désignation")))."\n";
}
echo json_encode($array);
?> |
Si j'appel manuelement le fichier "rechpieceri.php" comme ceci "http://localhost/projet/rechpieceri.php?term=c"
Il me retourne.
Code:
["PIECE1 - DESI PIECE 1","COUR001 - courroie diametre 100","CON001 - Contacteur 001","COUR002 - COUR002","COUR3 - COUR3"]
Cela m'a l'air valide.
Si je remplace :
Code:
1 2 3 4
|
$("#piece").autocomplete({
source : "rechpieceri.php"
}); |
Par
Code:
1 2 3 4
|
$("#piece").autocomplete({
source : availableTags
}); |
Cela marche parfaitement.
Une idée de ce que j'ai pu oublier ?
Merci