gpt4 book ai didi

javascript - 如何用php删除垃圾图标glyphicon

转载 作者:行者123 更新时间:2023-11-28 00:20:47 27 4
gpt4 key购买 nike

我正在生成一个包含数据的表。该表包含操作。其中一个操作是从该表(以及数据库)中删除一行。

但是,当我单击“Trash 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>

最佳答案

将其放入您的 <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();
}
}
});

});

引用jquery.ajax了解更多 ajax 选项。

你需要处理很多事情,比如ajax中的URL是否是同一页面,那么在PHP中你将检查它是否是ajax请求,仅回显data而不是形式等...

关于javascript - 如何用php删除垃圾图标glyphicon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30050248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com