jQuery的自动完成不适用于PHP MySQL的 [英] jquery autocomplete is not working with php mysql

查看:65
本文介绍了jQuery的自动完成不适用于PHP MySQL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用PHP MySQL测试自动完成的文本框jquery以获取客户端名称,不会从数据库中检索数据.

Testing a autocomplete textbox jquery with PHP MySQL to get client name, data is not retrieving from the database.

我在这里提供PHP脚本表结构和HTML.我找不到问题...

I am giving here the PHP script table structure and HTML. I am not able to find the issue...

我已经读过一些与此有关的问题,但是没有什么能解决我的问题,实际上我是jquery新手

I had already read some questions regarding this but nothing solve my problem actually I am new to 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 consol错误

无法加载资源:服务器响应状态为404(未找到) 这是问题

Failed to load resource: the server responded with a status of 404 (Not Found) this is the problem

推荐答案

1.404问题是由于最近使用Ubuntu关闭错误显示后,我修复了问题,让我永久性地更新并关闭了该问题. 感谢您的帮助.

1.404 issue is due to my error display is off using Ubuntu recently after that I fix the problem let me update and close the problem for good.. thanks for helping..

$(document).ready(function () {
    $("#clientName").autocomplete({
        source: 'php_action/fetchClient.php'

    });
});

<?php
    include('core.php');
    //get search term
    $searchTerm = $_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);
?>

这篇关于jQuery的自动完成不适用于PHP MySQL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆