gpt4 book ai didi

php - jquery自动完成将不会显示数据

转载 作者:行者123 更新时间:2023-11-29 22:30:24 25 4
gpt4 key购买 nike

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

请帮忙!

最佳答案

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

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

关于php - jquery自动完成将不会显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29858110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com