<tfoot id='tolSX'></tfoot>
    <bdo id='tolSX'></bdo><ul id='tolSX'></ul>
  1. <i id='tolSX'><tr id='tolSX'><dt id='tolSX'><q id='tolSX'><span id='tolSX'><b id='tolSX'><form id='tolSX'><ins id='tolSX'></ins><ul id='tolSX'></ul><sub id='tolSX'></sub></form><legend id='tolSX'></legend><bdo id='tolSX'><pre id='tolSX'><center id='tolSX'></center></pre></bdo></b><th id='tolSX'></th></span></q></dt></tr></i><div id='tolSX'><tfoot id='tolSX'></tfoot><dl id='tolSX'><fieldset id='tolSX'></fieldset></dl></div>

    <legend id='tolSX'><style id='tolSX'><dir id='tolSX'><q id='tolSX'></q></dir></style></legend>

    1. <small id='tolSX'></small><noframes id='tolSX'>

      来自数据库的 JQuery 自动完成

      时间:2023-10-12
        <i id='wjV3A'><tr id='wjV3A'><dt id='wjV3A'><q id='wjV3A'><span id='wjV3A'><b id='wjV3A'><form id='wjV3A'><ins id='wjV3A'></ins><ul id='wjV3A'></ul><sub id='wjV3A'></sub></form><legend id='wjV3A'></legend><bdo id='wjV3A'><pre id='wjV3A'><center id='wjV3A'></center></pre></bdo></b><th id='wjV3A'></th></span></q></dt></tr></i><div id='wjV3A'><tfoot id='wjV3A'></tfoot><dl id='wjV3A'><fieldset id='wjV3A'></fieldset></dl></div>

            <small id='wjV3A'></small><noframes id='wjV3A'>

            <tfoot id='wjV3A'></tfoot>

          • <legend id='wjV3A'><style id='wjV3A'><dir id='wjV3A'><q id='wjV3A'></q></dir></style></legend>

            • <bdo id='wjV3A'></bdo><ul id='wjV3A'></ul>

                  <tbody id='wjV3A'></tbody>

              1. 本文介绍了来自数据库的 JQuery 自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要为我的网站提供自动完成建议,并且应该从数据库中检索数据.我想使用 JQuery 自动完成功能.这是我的代码,但它不起作用!这是我的名为 gethint.php 的 php 文件:

                I need to to do autocomplete suggestion for my website and the data should be retrieved from database. I want to use JQuery autocomplete. here is my code but it doesn't work! This is my php file with the name of gethint.php:

                <?php
                require_once ('config.php');
                $q=$_REQUEST["q"]; 
                $sql="SELECT `fname` FROM `Property` WHERE fname LIKE '%$q%'";
                $result = mysql_query($sql);
                $json=array();
                
                while($row = mysql_fetch_array($result)) {
                  $json[]=array(
                  'value'=> $row['fname'],
                  'label'=> $row['fname']
                   );
                   }
                   echo json_encode($json);
                  ?>
                

                然后这是我的 html 文件:

                and then this is my html file :

                <html>
                <head>
                <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
                <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
                <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
                 <script type="text/javascript"> 
                 $(document).ready(function(){                  
                 $("#hint").autocomplete({                        
                 source:'gethint.php', 
                 minLength:1                  
                   }); 
                   });        
                </script>
                </head>
                <body>
                <form class="sansserif" action="view.php" method="post">
                Name: <input type="text" id="hint" name="hint" >
                <input type="submit" name="submit" value="View">
                </form>
                </html>
                

                花了很多时间,但我找不到问题所在.我想知道是否有人可以帮助我.谢谢.

                It took a lot of time but I couldn't find the problem. I was wondering if someone could help me. Thanks.

                推荐答案

                我做了一些改动,也许你需要修复一些东西,但看看是否有帮助...

                I did some changes, maybe you need to fix something but take a look to see if helps...

                PHP:

                <?php
                    require_once ('config.php');
                
                    $q=$_REQUEST["q"]; 
                    $sql="SELECT `fname` FROM `Property` WHERE fname LIKE '%$q%'";
                    $result = mysql_query($sql);
                
                    $json=array();
                
                    while($row = mysql_fetch_array($result)) {
                      array_push($json, $row['fname']);
                    }
                
                    echo json_encode($json);
                ?>
                

                html+jquery:

                The html+jquery:

                <html>
                    <head>
                        <script src="//code.jquery.com/jquery-1.10.2.js"></script>
                        <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
                        <link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
                    </head>
                    <body>
                        <form class="sansserif" action="view.php" method="post">
                            Name: <input type="text" id="hint" name="hint" />
                            <input type="submit" name="submit" value="View">
                        </form>
                
                        <script type="text/javascript"> 
                
                        $(function() {
                            $( "#hint" ).autocomplete({
                                source: function( request, response ) {
                                    $.ajax({
                                        url: "gethint.php",
                                        dataType: "jsonp",
                                        data: {
                                            q: request.term
                                        },
                                        success: function( data ) {
                                            response( data );
                                        }
                                    });
                                },
                            });
                        });     
                        </script>
                    </body>
                </html>
                

                这篇关于来自数据库的 JQuery 自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:由数据库填充的自动完成表单? 下一篇:如何使用codeigniter让zend studio自动完成

                相关文章

                1. <tfoot id='jQwDO'></tfoot>

                  <small id='jQwDO'></small><noframes id='jQwDO'>

                    • <bdo id='jQwDO'></bdo><ul id='jQwDO'></ul>

                    <legend id='jQwDO'><style id='jQwDO'><dir id='jQwDO'><q id='jQwDO'></q></dir></style></legend>
                  1. <i id='jQwDO'><tr id='jQwDO'><dt id='jQwDO'><q id='jQwDO'><span id='jQwDO'><b id='jQwDO'><form id='jQwDO'><ins id='jQwDO'></ins><ul id='jQwDO'></ul><sub id='jQwDO'></sub></form><legend id='jQwDO'></legend><bdo id='jQwDO'><pre id='jQwDO'><center id='jQwDO'></center></pre></bdo></b><th id='jQwDO'></th></span></q></dt></tr></i><div id='jQwDO'><tfoot id='jQwDO'></tfoot><dl id='jQwDO'><fieldset id='jQwDO'></fieldset></dl></div>