Hi, I've a problem with JQuery autocomplete. I have to take some data from a MySQL db and then use the autocomplete on a form. The search works fine, if I add to the URL "test.php?term=a" I obtain the result that I expect, the problem is with the visualization of the results in the autocomplete, in the dropdown menu there are no names, just a thin gray bar. I post my code and a screenshot.
This is the jQuery script
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="container.css">
- <link rel="stylesheet" href="jquery-ui-1.9.2.custom/development-bundle/themes/base/jquery.ui.all.css"/>
- <script src="jquery-ui-1.9.2.custom/js/jquery-1.8.3.js"></script>
- <script src="jquery-ui-1.9.2.custom/js/jquery-ui-1.9.2.custom.js"></script>
- <script src="jquery-ui-1.9.2.custom/development-bundle/ui/jquery.ui.core.js"></script>
- <script src="jquery-ui-1.9.2.custom/development-bundle/ui/jquery.ui.widget.js"></script>
- <script src="jquery-ui-1.9.2.custom/development-bundle/ui/jquery.ui.position.js"></script>
- <script src="jquery-ui-1.9.2.custom/development-bundle/ui/jquery.ui.autocomplete.js"></script>
- <script>
- $(document).ready(function(){
- $("#autoCompleteName").autocomplete({
- source: 'test.php',
- dataType: 'json'
- });
- });
- </script>
- </head>
- <body>
And this is the php file:
- <?php
- require_once('Model.class.php');
- $test = new Model();
- $test -> connectDB();
- $arr = array();
- $name = 'nome';
- $codice = 'codice';
- $return = array();
- $query = "SELECT * FROM toponimo WHERE nome LIKE '%".$_REQUEST['term']."%'";
- $result = mysql_query($query);
- while($row = mysql_fetch_array($result))
- {
- $arr['id'] = $row[$codice];
- $arr['nome'] = $row[$name];
- array_push($return, $arr);
- }
- $test -> closeConnectionDB();
- echo json_encode($return);
- ?>
And this is what I obtained with the from:
Can somebody help me?
Thanks