简体   繁体   English

如何使用PHP删除垃圾箱图标glyphicon

[英]How to delete on the trash icon glyphicon with php

I am generating a table with data. 我正在生成带有数据的表。 the table contains action. 该表包含动作。 and one of those actions is to delete a row from that table (and from the database). 这些动作之一就是从该表(和数据库)中删除一行。

But how can i manage to delete a row when i click on the Trash Glyphicon without moving to another page. 但是,当我单击“垃圾桶Glyphicon”而不移动到另一页面时,如何设法删除一行。

<form action ="" method="POST">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Categorie naam</th>
                            <th>Afbeelding</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    <?php
                        $sqli = "SELECT * FROM category ORDER BY category_id";
                        $result = $connect->query($sqli);
                        if($result->num_rows < 0){
                            echo "<div class='alert alert-warning' role='alert'><strong>Oh oh! </strong>Er zijn geen categori&euml;n. <br></div>";
                        }
                        else{
                            while ($row=mysqli_fetch_assoc($result)){
                                $category[] = $row;
                            }
                            foreach($category as $value){
                                echo '<tr>';
                                echo    '<td>'.$value['category_id'].'</td>';
                                echo    '<td>'.$value['category_name'].'</td>';
                                echo    '<td>'.$value['c_filename'].'</td>';
                                echo    '<td>';
                                echo        '<a href="../../cms/content/category_management.php?page=alter_category&id='.$value['category_id'].'"><span class="glyphicon glyphicon-pencil"></span></a> / ';
                                echo        '<a href="../../cms/content/category_management.php?delete_category.php&id='.$value['category_id'].'" data-toggle="modal" data-target="#confirm-delete"><span class="glyphicon glyphicon-trash" id="submit" name="submit"></span></a>';
                                echo    '</td>';  
                                echo '</tr>';
                            }       
                        }
                    ?>
                    </tbody>
                </table>
            </form> 

Put this in your <script> tag at the very bottom of the page. 将其放在页面底部的<script>标记中。

$(".glyphicon-trash").click(function(){

    $.ajax({
      url: "http://url/to/php/page.php",
      type: "POST",
      success: function( data ) {
        // From the response in data, you should be able to
        // know if delete was successful
        console.log(data);
        // your js code to remove the row
        // even I am not good with js/jquery
        if(data.success){ // example
          this.closest("tr").hide();
        }
      }
    });

});

Refer jquery.ajax for more ajax options. 有关更多ajax选项,请参考jquery.ajax

You need to handle many things like if the URL in ajax is same page, then in PHP you will have check if its the ajax request, echo just the data instead of form, etc... 您需要处理很多事情,例如ajax中的URL是同一页,然后在PHP中您将检查其ajax请求,仅回显data而不是表单等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将删除垃圾桶图标添加到 React 中的引导表行? - How to add delete trash icon to bootstrap table rows in React? 当有人单击“垃圾箱”图标时,如何删除特定的 localStorage,它会在前端而不是本地删除它 - How do I delete a specific localStorage when someone click a “trash” icon, which gets rid of it frontend but not local 如何在点击事件中更改glyphicon图标类? - How to change glyphicon icon class on click event? 通过将事件拖到完整日历 V 2 之外来删除事件(带或不带垃圾桶图标......) - Delete event by dragging it outside of the full calendar V 2 (with or without trash icon…) 如何使可点击的日期选择器glyphicon-calender图标正常工作? - How to make a clickable datepicker glyphicon-calender icon to work properly? 如何在Django模板的跨度切换中切换glyphicon图标 - How to toggle glyphicon icon on toggle of a span in django templates 如何在Java脚本中使垃圾箱图标清除文本区域? - How do I make a trash icon clear a text area in java script? 我如何构建百分数glyphicon星状图标以填充十进制平均评分? - How do i build percentage glyphicon star icon to fill decimal average rating? AngularJS - 显示和隐藏带有glyphicon的箭头图标 - AngularJS - show and hide arrow icon with glyphicon Bootstrap Glyphicon错误:正方形而不是图标 - Bootstrap glyphicon error: square instead of icon
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM