jquery自动完成不会显示数据

时间:2015-04-24 21:50:32

标签: php jquery mysql ajax json

请原谅我,如果我不使用正确的条款,我是初学者,我正在努力建立自己的动态网站。我的问题是jquery自动完成。我无法让它在网页上显示数据。 我一直在阅读论坛和观看视频一周。我已经尝试过几十个脚本。似乎没什么用。

这是有效的jquery:

 </style>

 <link rel="stylesheet" href="css/jquery-ui-1.11.4-themes- smoothness.css">
<script src="js/jquery-1.10.2.js"></script>
<script src="js/jquery-ui-1.11.4-ui.js"></script>

<script type="text/javascript">
 $(function() {
 $( "#search_bars" ).autocomplete({
source: ['Bob', 'Ted', 'Bruce', 'Alice'],
minLength: 2

});
});
</script>

这是不起作用的jquery:

 <link rel="stylesheet" href="css/jquery-ui-1.11.4-themes-smoothness.css">

   

<script type="text/javascript">
 $(function() {
 $( "#search_bars" ).autocomplete({
source: 'js/ajax.php',
minLength: 2

});
});
</script>

这是ajax.php代码:

    <?php 
    include_once '../reviews.class2.php';

    $reviews = new Reviews();

    echo json_encode($reviews->search_bars($_GET['term']));

    ?>

最后,这里是reviews.class2.php代码:

<?php 
require('Connections/db_conn.php');?>
<?php
mysql_select_db($database_db_conn, $db_conn) or die("could not find db");

class  Reviews
{
public function _construct(){
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'dbpassword';
    $dbname = 'dbname';

    mysql_connect($dbhost, $dbuser, $dbpass);

    mysql_select_db($dbname);


}
public function search_bars($name){
    $data = array();

    $sql = "SELECT * FROM listing WHERE Name LIKE '%$name%' OR City LIKE '%$name%' ORDER BY Name LIMIT 10";

    $result = mysql_query($sql) or die(mysql_error());


    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
        $data[] = array("value" => $row['Name'] . ' ' .
                                   $row['City']);
        }

    return $data;
    }
    }

当我在浏览器中预览ajx.php页面时,我看到了json数据:

Notice: Undefined index: term in C:\xampp\htdocs\js\ajax.php on line 6

[{"value":"88?s Dueling Pianos Hollywood"},{"value":"All Stars Sports Bar and Grill Pompano Beach"},{"value":"America?s Backyard Fort     Lauderdale"},{"value":"American Rock Restaurant Bar and Grill Deerfield Beach"},{"value":"B.E.D. Miami Beach"},{"value":"Bamboo Beach Fort Lauderdale "},{"value":"Bamboo Room Lake Worth"},{"value":"Bardot Miami"},{"value":"Beach Betty?s Dania Beach"}, {"value":"Best Cellar Wilton Manors "}]

问题是json数据没有出现在

请帮忙!

1 个答案:

答案 0 :(得分:0)

我认为我有一个类似的问题,直到我覆盖自动完成样式......

<style type="text/css">
    .ui-autocomplete { max-height: 150px; overflow-y: auto; overflow-x: hidden; font-size: 9pt; }
    * html .ui-autocomplete { height: 100px; }
</style>