【发布时间】:2019-08-23 10:19:32
【问题描述】:
我想通过点击删除按钮来删除一行。
我已经编辑了行中的数据。我想删除行中的数据。删除操作不起作用。
db.php
<script>
$(document).ready(function() {
$.ajax({
url: "View_ajax.php",
type: "POST",
cache: false,
success: function(dataResult){
$('#table').html(dataResult);
}
});
$(document).on("click", ".delete", function() {
var $ele = $(this).parent().parent();
$.ajax({
url: "delete_ajax.php",
type: "POST",
cache: false,
data:{
id: $(this).attr("data-id")
},
success: function(dataResult){
var dataResult = JSON.parse(dataResult);
if(dataResult.statusCode==200){
$ele.fadeOut().remove();
}
}
});
});
});
</script>
delete_ajax.php
<?php
include "php/dbConfig.php";
$id=$_POST['id'];
$sql = "DELETE FROM `task` WHERE id=$id";
if (mysqli_query($conn, $sql)) {
echo json_encode(array("statusCode"=>200));
}
else {
echo json_encode(array("statusCode"=>201));
}
mysqli_close($conn);
?>
view_ajax.php
<td><input type='button' onclick="delete_user('<?php echo $row['id'];?>');"
data-id="<?=$row['id'];?>"
data-firstname="<?=$row['firstname'];?>"
data-lastname="<?=$row['lastname'];?>"
data-username="<?=$row['username'];?>"
data-password="<?=$row['password'];?>"
"></button></td>
by clicking the delete button i want the entire row to be deleted.
删除功能不起作用。请帮助我。
【问题讨论】:
-
您可能需要向我们展示您在 delete_ajax.php 中的代码,如果可以的话,或许可以解释一下具体问题。
-
我已经添加了我尝试过的代码。请检查一下。
-
$(document).on("click", ".delete", function() {我看不到带有“删除”类的 html 标记...