duanliaoyu8419 2018-05-21 06:08
浏览 122

选择自动完成ui Jquery后加载数据

I want to display row details after selecting a jquery auto complete input using json array ajax function i have auto complete ui code jquery autocomplete is not working with php mysql . I try to extend its functionality but failed. here is my attempt. thanks for reading and helping

    <div class="col-lg-9">
                    <input type="text" id="clientName" class="form-control" autocomplete="off">
                </div>
                <div class="table-responsive" id="client_details" style="display:none">
                    <table class="table table-bordered">
                        <tr>
                            <td><b>Client Name</b></td>
                            <td>
                                <spam id="lblClientName"></spam>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Client Company name </b></td>
                            <td>
                                <spam id="lblClientCompanyName"></spam>
                            </td>
                        </tr>
                        <tr>
                            <td><b>Address</b></td>
                            <td>
                                <spam id="clientAddress"></spam>
                            </td>
                        </tr>
                        <tr>

                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </form>
    <script src="js/order.js" type="text/javascript"></script>

    **jquery**

            $(document).ready(function () {
    $("#clientName").autocomplete({
        source: 'php_action/fetchClient.php',
        select: function( event, ui ) {
        var clientName = $('#clientName').val();
        if (clientName != '') {
            $.ajax({
                url: "php_action/fethClientByName.php",
                method: "POST",
                data: {
                    clientName: clientName
                },
                dataType: "JSON",
                success: function (data) {
                    $('#client_details').css("display", "block");
                    $('#lblClientName').text(data.clientName);
                    $('#lblClientCompanyName').text(data.companyName);
                }
            })
        } else {

            $('#client_details').css("display", "none");
        }   
    }
    });
});


    **php file**

            <?php   

        require_once 'core.php';

        $clientName = $_POST['clientName'];

        $sql = "SELECT * FROM client WHERE client_Name = $clientName";
        $result = mysqli_query($con, $sql);
        while($row = mysqli_fetch_array($result))
         { 
            $data['clientName'] = $row['client_Name'];
                $data['companyName'] = $row['client_Company_Name'];
                $data['companyAddress'] = $row['client_Company_Address']; 
        } 

        $con->close();

        echo json_encode($data);
        ?>

    **db connection file** 


        <?php   

        $localhost = "localhost";
        $username = "root";
        $password = "admin";
        $dbname = "stock";

        // db connection
        $con = new mysqli($localhost, $username, $password, $dbname);
        // check connection
        if($con->connect_error) {
          die("Connection Failed : " . $con->connect_error);
        } else {
        //   echo "Successfully connected";
        }

        ?>
  • 写回答

2条回答 默认 最新

  • duanbi7204 2018-05-21 06:21
    关注
    Hi **Harish**,
    
    Use the options for autocomplete to get the required output. Try 'select' in the autocomplete.
    
    $( "#clientName" ).autocomplete({
      select: function( event, ui ) {
        // Write the code here
      }
    });
    
    This will help you in the desired solution. For more details of the events, http://api.jqueryui.com/autocomplete/
    
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致