<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 自动完成

      JQuery Autocomplete from Database(来自数据库的 JQuery 自动完成)
        <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 自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                  • <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>
                        • <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>
                            <tbody id='jQwDO'></tbody>