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条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据