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

<small id='5QSIR'></small><noframes id='5QSIR'>

  1. <legend id='5QSIR'><style id='5QSIR'><dir id='5QSIR'><q id='5QSIR'></q></dir></style></legend>

      • <bdo id='5QSIR'></bdo><ul id='5QSIR'></ul>
    1. jQuery 自动完成 Mysql PHP

      时间:2023-10-12

        <tfoot id='BLl6Z'></tfoot>

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

              <tbody id='BLl6Z'></tbody>
              <bdo id='BLl6Z'></bdo><ul id='BLl6Z'></ul>

            • <i id='BLl6Z'><tr id='BLl6Z'><dt id='BLl6Z'><q id='BLl6Z'><span id='BLl6Z'><b id='BLl6Z'><form id='BLl6Z'><ins id='BLl6Z'></ins><ul id='BLl6Z'></ul><sub id='BLl6Z'></sub></form><legend id='BLl6Z'></legend><bdo id='BLl6Z'><pre id='BLl6Z'><center id='BLl6Z'></center></pre></bdo></b><th id='BLl6Z'></th></span></q></dt></tr></i><div id='BLl6Z'><tfoot id='BLl6Z'></tfoot><dl id='BLl6Z'><fieldset id='BLl6Z'></fieldset></dl></div>
              <legend id='BLl6Z'><style id='BLl6Z'><dir id='BLl6Z'><q id='BLl6Z'></q></dir></style></legend>
              • 本文介绍了jQuery 自动完成 Mysql PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有人可以看看这个,让我知道我哪里出错了.我正在尝试让 jQuery UI 自动完成工作.这是我的代码:这是search.php

                include "db_connect.php";$search = $_GET['term'];$result = mysql_query("SELECT Title FROM `movie` WHERE `Title` LIKE '%$search%' ORDER BY Title ASC") or die('出了问题');$rows = array();而 ($row = mysql_fetch_assoc($result)){$rows[] = $row;}打印 json_encode($rows);?>

                这是我的 javascript 内联脚本

                这是自动"div

                <p><input type="text" id="auto"/></p>

                当我使用 firebug 查看调用时,我看到 search.php 正在返回

                [{"Title":"罪恶之城"}]

                jQuery 只是显示 UNDEFINED有什么想法吗??

                解决方案

                查看 jquery ui 自动完成文档.您返回的 JSON 与自动完成功能正在寻找的内容不匹配.您返回的对象必须具有名为 label 或 value(或两者)的属性.

                您可以尝试以下选项:

                选项 1:更改返回的 JSON

                更改返回的 JSON 以包含标签/值属性,例如:

                [{标签":罪恶之城"}]

                从示例中它似乎也使用了 id 属性.我相信以上是自动完成显示值列表的最低要求.我认为你也可以返回一个字符串数组,它会以与上面完全相同的方式呈现它.

                [ 《罪恶之城》、《等等》]

                选项 2:更改私有 _render 函数

                更改自动完成的私有 _renderItem 函数以使用您的自定义属性,如此 自动完成示例所示(未经测试):

                $( "#project" ).autocomplete({来源:./search.php",最小长度:3}).data(自动完成")._renderItem = function( ul, item ) {返回 $( "
              • ").data( "item.autocomplete", item ).append( item.Title ).appendTo(ul);};

                这有点灵活,但恕我直言更丑陋.

                Hi could some one please take a look at this and let me know where I'm going wrong. I am trying to get jQuery UI autocomplete to work. this is my code: This is search.php

                include "db_connect.php";
                $search = $_GET['term'];    
                    $result = mysql_query("SELECT Title FROM `movie` WHERE `Title` LIKE '%$search%' ORDER BY Title ASC") or die('Something went wrong');
                    $rows = array();
                    while ($row = mysql_fetch_assoc($result)){
                        $rows[] = $row;
                
                    }
                print json_encode($rows);
                ?>
                

                this is my javascript inline script

                <script type="text/javascript">
                    $(document).ready(function()
                    {
                        $('#auto').autocomplete(
                        {
                            source: "./search.php",
                            minLength: 3
                        });
                    });
                </script>
                

                and this is the 'auto' div

                <div id="searchTxtFieldDiv">
                <p><input type="text" id="auto" /></p>
                </div>
                

                When I look at the call using firebug I see that search.php is returning

                [{"Title":"Sin City"}]
                

                jQuery is just displaying UNDEFINED any ideas??

                解决方案

                Have a look at jquery ui autocomplete documentation. The JSON you are returning does not match what the autocomplete is looking for. The object you return must have properties named label or value (or both).

                You can try the following options:

                Option 1: Change returned JSON

                Change the JSON being returned to include the label/value properties such as:

                [{"label":"Sin City"}]
                

                From the examples it also seems to use the id property. I believe the above is the minimum requirement for the autocomplete to display a list of values. I think you can also return an array of strings and it will render it in exactly the same way as the above.

                [ "Sin City", "Etc" ]
                    
                

                Option 2 : Change private _render function

                Change the private _renderItem function for the autocomplete to use your custom properties as shown in this autocomplete example (untested):

                $( "#project" ).autocomplete({
                    source: "./search.php",
                    minLength: 3    
                })
                .data( "autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                   .data( "item.autocomplete", item )
                   .append( item.Title )
                   .appendTo( ul );
                };
                

                This is a bit more flexible but much uglier imho.

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

                上一篇:在 PHP 中按引用返回 下一篇:由数据库填充的自动完成表单?

                相关文章

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

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

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

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