Problem with autocomplete.
Hi everybody,
I have a problem with autocomplete.
The source data are stored in database.
Ajax calls citta.php, that should give the name of the town when I start writing.
<script>
$( "#campo" ).autocomplete({
minLength: 2,
source: "citta.php"
});
</script>
Instead if I use an array where I write some towns it works good.
citta.php:
$return_arr = array();
include("../Registrazione/config.php"); //connect to database
if (isset($_GET) && isset($_GET['term']) && !empty($_GET['term'])) {
$term = $_GET['term'];
$query = "SELECT * FROM comuni WHERE comune LIKE '%{$term}%' ORDER BY comune ASC";
$fetch = mysql_query($query);
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
$row_array['label'] = $row['comune'];
$row_array['value'] = $row['id_com'];
array_push($return_arr, $row_array);
}
}
echo json_encode($return_arr);
Please, can someone helps me?
Thanks in advance.
Tegatti