0
如果我在刪除記錄後出現ID,則在控制檯中顯示正確的ID。所以,它似乎是正確連接,但實際上並沒有從我的數據庫中刪除記錄。我無法弄清楚,但它可能是明顯的。使用php/ajax記錄沒有刪除
JS
<script type="text/javascript">
$(document).ready(function() {
$('.table-row').on('click', function (e) {
e.preventDefault();
var $otId = $(this).data('ot-id');
swal({
title: 'Are you sure?',
text: "You won't be able to undo this!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#FB404B',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!',
closeOnCancel: false
}, function (isConfirm) {
if (isConfirm) {
$.ajax({
type: 'post',
url: 'functions/delete-ot-request.php',
data: {otId: $otId},
success: function (result) {
// window.location.href = 'delete-ot.php';
console.log($otId);
},
});
} else {
swal("Cancelled", "Maybe next time then.", "error");
}
});
});
});
</script>
PHP
if(isset($_POST['otId'])) {
$stmt = $link->prepare("DELETE FROM `ot_request` WHERE `id` = ? LIMIT 1");
$stmt->bind_param("i", $_POST['otId']);
$stmt->execute();
$stmt->close();
}
這是一個包含ID的HTML表格行:
<tr class="table-row" data-ot-id="{$id}"></tr>
你能充分展現html代碼!因爲你發佈tr不可能點擊沒有td –
改進的格式 – purvik7373