试图弄清楚这一个几个小时,没有运气。 根据firebug的确切错误是:TypeError:items [0]为null http://localhost:81/tab/resources/jquery-ui.js 第8488行
,代码是:
<html>
<head>
<link rel="stylesheet" href="resources/jquery-ui.css">
<script src="resources/jquery-3.1.1.js"></script>
<script src="resources/jquery-ui.js"></script>
<script>
$(function() {
$( "#skills" ).autocomplete({
source: 'search.php',
minLength: 3
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="skills">Skills: </label>
<input id="skills">
</div>
</body>
</html>
的search.php:
<?php
require("db.php");
$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
$key = $_GET['term'];
$query = mysqli_query($connection, "SELECT * FROM sz55 WHERE name LIKE '%{$key}%' AND ejszakak BETWEEN 1 AND 100");
while($row = mysqli_fetch_assoc($query)) {
$data[] = $row['name'];
}
echo json_encode($data);
mysqli_close($connection);
?>
请帮助:D
答案 0 :(得分:0)
事实证明,问题是我的数组中有特殊字符来自查询。只需添加mysqli_set_charset($ connection,“utf8”);到search.php解决了这个问题。