【问题标题】:jquery autocomplete will not display datajquery自动完成不会显示数据
【发布时间】:2015-04-24 21:50:31
【问题描述】:

如果我没有使用正确的术语,请原谅我,我是这方面的初学者,我正在尝试建立自己的动态网站。我的问题是 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数据没有显示在

请帮忙!

【问题讨论】:

  • 另外我认为您需要修复 ajax.php 第 6 行中的未定义术语,自动完成对 json 结果集非常挑剔,因此它看到该错误并且根本不返回任何内容

标签: php jquery mysql ajax json


【解决方案1】:

我认为在覆盖自动完成样式之前我遇到了类似的问题...

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

【讨论】:

    猜你喜欢
    • 2018-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多