php - jquery 自动完成功能不适用于 php mysql

标签 php jquery mysql

使用 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/

相关文章:

PhpStorm 如何更改用户的默认签名?

php - 如何制作一个多语言的 php 站点?

php - 如何从 url 获取 Facebook 页面用户名或 facebook 页面 ID

jquery - 带有响应式 slider /图库的响应式 html5 模板

javascript - 当前位置路径作为 url 参数

mysql - SSRS 报告数据库版本之间的被动性

javascript - php 中的分页。 AJAX、PHP、MYSQL

javascript - 检查标签文本并验证与其关联的输入字段至少有 x 个字符

MySQL 在子查询中插入自动生成的列

php - 如何添加具有外键值的表引用 Laravel 中的另一个表?