使用 PHP MySQL 测试自动完成文本框 jquery 以获取客户端名称,未从数据库检索数据。
我在这里给出了 PHP 脚本表结构和 HTML。我找不到问题...
我已经阅读了一些与此相关的问题,但没有解决我的问题,实际上我是 jquery 的新手
谢谢
HTML
<html>
<head>
<title>Document</title>
<!-- jquery -->
<script src="assests/jquery/jquery.min.js"></script>
<!-- jquery ui -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$('#clientName').autocomplete({
source: 'php_action/fetchClient.php',
minLength: 2,
response: function(event, ui) {
// ui.content is the array that's about to be sent to the response callback.
if (ui.content.length === 0) {
$("#empty-message").text("No results found");
}
else {
$("#empty-message").empty();
}
}
});
</script>
</head>
<body>
<input type="text" id="clientName" class="form-control" autocomplete="on">
</body>
</html>
PHP 脚本
<?php
//get search term
$searchTerm = trim ($_GET['term']);
//get matched data from skills table
$query = $con ->query("SELECT * FROM client WHERE client_Name LIKE '%".$searchTerm."%' ORDER BY client_Name ASC");]\
while ($row = $query->fetch_assoc()) {
$data[] = $row['client_Name'];
}
//return json data
echo json_encode($data);
?>
数据库表
INSERT INTO `client` (`clientID`, `client_Name`, `client_Company_Name`, `client_status`, `client_Company_Address`, `client_GST_Number`, `client_Mobile`, `client_Landline`) VALUES
(1, 'test', '', b'1', 'rohini delhi', 0, 0, 0),
(2, 'bbb', '', b'0', '', 33333, 2222, 33312),
(3, 'AAA', '', b'0', '', 33333, 2222, 33312),
(4, 'ccc', '', b'0', '', 33333, 2222, 33312);
Dom 控制台错误
Failed to load resource: the server responded with a status of 404 (Not Found) this is the problem
最佳答案
我发现了一些问题。
1) 404 问题仅在您的来源
错误时发生。
2) 在您的 PHP 脚本中,mysql
查询行之后有一个额外的 ]\
。
3) 如果您只需要 client_Name
,则仅获取 client_Name
而不是 *
关于php - jquery 自动完成功能不适用于 php mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50251596/