doutao4938 2019-07-01 17:25
浏览 73

如何在Wordpress中的自定义插件的管理面板中创建一个表的实时搜索?

I'm new to Wordpress plugin developement, and I'm trying to create a live search for a HTML table in admin panel for my Wordpress plugin, but I have no idea how to refer the search to the table in the panel. My guess the problem is with the url in the jQuery AJAX call.

When I put the url of my index.php file, it just copies the whole wordpress page.

Here is the code:


    function ecommerce_plugin_menu(){
        $connection = mysqli_connect('localhost', 'root', '', 'wordpresssite') or die("couldn't connect");
        echo "<input type='text' name='search_text' id='search_text' />";
        echo "<div id='result'>";
        echo "<table style='border: 1px solid black'>"; // start a table tag in the HTML
        echo "<tr><th><a href='admin.php?page=ecommerce&sort=first'>First Name</a></th><th><a href='admin.php?page=ecommerce&sort=last'>Last Name</a></th><th><a href='admin.php?page=ecommerce&sort=address'>Address</a></th><th><a href='admin.php?page=ecommerce&sort=email'>E-mail</a></th></tr>";
        $query = "SELECT * FROM wp_ecommerce_fs";
    $result = mysqli_query($connection, $query);

        while($row = mysqli_fetch_array($result)){   //Creates a loop to loop through results
        echo "<tr><td>" . $row['first_name'] . "</td><td>" . $row['last_name'] . "</td><td>". $row['address'] . "</td><td>" . $row['email'] . "</td></tr>";  
        }
        echo "</table>";
        echo "</div>";
        echo "<script>
        jQuery(document).ready(function(){
            jQuery('#search_text').keyup(function(){
                var txt= jQuery(this).val();
                if(txt != '')
                {
                jQuery.ajax({
                        url: plugin_dir_url('index.php'),
                        method:'post',
                        data:{search:txt},
                        dataType:'text',
                        success:function(data)
                        {
                            jQuery('#result').html(data);
                        }
                    });
                }
                else
                {
                    jQuery('#result').html('');

                }
            });
        });</script>";
    }

I want to search the contents of the HTML table directly if whatever in the table matches the user input. What would be the correct url in AJAX call?

Thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记