doulin6761 2019-08-06 06:05
浏览 53
已采纳

如何在不使用JavaScript重新加载页面的情况下在数据库中执行操作?

I've wrote a code which retrieve some data in table and each row has a two button which is responsible for updating database with a fixed value for that row and deleting the row. I want to do these actions without reloading page. here is my table code:

<table id="example1" class="table table-bordered table-striped">
    <thead>
    <tr>
        <th>نام کاربر</th>
        <th>ایمیل</th>
        <th>تایید</th>

    </tr>
    </thead>
    <tbody>
    <?php
    while ($users = mysqli_fetch_assoc($result_user)) {
        ?>
        <tr>
            <td><?php echo $users['name']?></td>
            <td><?php echo $users['email']?></td>
            <td>
                <div class="btn-group">
                    <button name="btn_confirm" type="button" class="btn btn-success btn-flat">تایید</button>
                    <button type="button" class="btn btn-success btn-flat dropdown-toggle" data-toggle="dropdown">
                        <span class="caret"></span>
                        <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li><a name="btn_delete" href="#">حذف</a></li>
                    </ul>
                </div>
            </td>
        </tr>
    <?php }?>
    </tbody>
</table>
  • 写回答

2条回答 默认 最新

  • douxian5963 2019-08-06 09:29
    关注

    You need to use AJAX as @Sagar Sainkar said.

    You can find a good explanation on this post:

    jQuery Ajax POST example with PHP

    So I will not rewrite the whole mechanism again. It explains very well how you can plat with ajax, js and php (which I noticed you use).

    Another TIP: avoid mixing up back-end and front-end code. Don't integrate php scripts in HTML files. Try writing separate JS files (containing the requests), import them into your HTML code and use them there (and if they do not load graphical content that the user needs to see when the page loads, then defer it, or put the import of the JS at the bottom of html). There may be better options but one easy to delete or update rows using AJAX is to pass a parameter to the server like "command: delete_entry" or something similar and then switch between options on the back end. But there are smarter options out there if you research well, you can use this tip plus the tutorial passed to start playing with AJAX requests until you master get a good grip upon them.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来