我正在生成一个包含数据的表。该表包含操作。其中一个操作是从该表(以及数据库)中删除一行。
但是,如果我点击“垃圾箱字形”而不移动到另一个页面,我怎么能设法删除一行。
<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ë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>
答案 0 :(得分:1)
将其放在页面底部的<svg viewbox="0 0 10 2">
<text x="5" y="1" text-anchor="middle" font-size="1" fill="none" stroke-width=".015" stroke="#fff" font-family="sans-serif">Text stroke</text>
</svg>
标记中。
<script>
有关更多ajax选项,请参阅jquery.ajax。
你需要处理很多事情,比如如果ajax中的URL是同一页面,那么在PHP中你将检查它是否是ajax请求,只回显$(".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();
}
}
});
});
而不是表单等等......