Проблема в том, что вы не используете ajax для удаления строки, вы используете якорный тег по умолчанию, который перенаправляет вас на другую страницу, если вы хотите реализовать ajax, вы должны сделать что-то вроде этого:
Добавьте атрибут класса и данных для удаления привязки:
// delete-row class added
echo "<a class='btn-view btn-danger btn-sm delete-row' data-report-id='<?php echo $row[report_id] ?>' href=\"delete.php?report_id=$row[report_id]\" onClick=\"return confirm('Do you want to remove team?')\">Remove</a></td>";
Добавьте прослушиватель события щелчка для этого класса:
$(document).on('click', '.delete-row', function(e) {
// prevents a tag from redirecting to another page
e.preventDefault();
// id of selected row
let rowId = $(this).data('report-id');
// validate row id here if you want
...
// trigger ajax to delete.php
$.ajax({
url: '/pathto/delete.php',
type: 'GET',
data: {report_id: rowId },
success: function( response ) {
response = JSON.parse( response );
// delete row html if response is successful, otherwise display an error
if (response.status == 'success') {
// remove html here
} else {
// append error message here
}
},
error: function (xhr, status, error) {
console.log( xhr.responseText );
}
});
});
Наконец, обновите удаляемое. php это:
<?php
//including the database connection file
require_once '../../../config/configPDO.php';
//getting id of the data from url
$report_id = $_GET['report_id'];
$sql = "DELETE FROM ot_report WHERE report_id=:report_id";
$query = $conn->prepare($sql);
if($query->execute(array(':report_id' => $report_id))) {
echo json_encode([
'status' => 'success',
]);
} else {
echo json_encode([
'status' => 'error',
]);
}
exit();
?>