将数据库中的结果显示为texbox中的列表

时间:2017-07-22 13:11:34

标签: php ajax

我正在使用以下脚本从数据库中检索keyup上的数据

  <script>
                $(function(){
                    $('.input').keyup(function(){
                        var a = $('.input').val();
                        $.post('actions/action_user_search.php',{"search":a},function(data){
                            //show results 
                            $('#display').html(data);
                        });
                    });
                });

    </script>

我想将结果显示为文本框内的列表,而不是文本框下面的

see example

echo '<h1>Search User</h1>
    <form action= "actions/action_user_search.php" method="POST" >
        <input type="text" name="search" class="input">
        </form>
        <div id="display" style="margin-top:50px" ></div>';

如何在文本框中以列表形式显示结果,而不是使用此处显示的方式(在div id = display中)

由于

1 个答案:

答案 0 :(得分:0)

您使用了错误的选择器。如果data是字符串,则此代码会将文本设置为文本框:

$('input[name=search]').val(data);

如果响应data是HTML代码,则必须先解析它,提取列表项,然后设置为文本框