I encountered an error when the error function is triggered from sweet alert. How can I resolve this issue? Appreciate any help!
SweetAlert: Missing "title" argument!
Here is my JavaScript code:
function DeletePost() {
swal({
title: "Are you sure?",
text: "This operation is irreversible and will delete the communication along with its connected comments from the database!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete communication!",
cancelButtonClass: "btn btn-danger",
cancelButtonText: "No, do not proceed!",
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if (isConfirm) {
$.ajax({
url: "../delete_all.php",
method: "POST",
dataType: 'json',
success: function(response) {
// swal('Deleted!', response.message, response.status);
swal({
title: response.title,
text: response.message,
type: response.status
},
function(){
location.reload();
}
);
},
error: function(response) {
swal({
title: response.title,
text: response.message,
type: response.status
});
}
});
} else {
swal("Cancelled!", "Operation cancelled successfully!", "error");
}
});
}
And here is my PHP file:
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Fetch the administrator's id and assign it to a variable
$userid = $_SESSION['user_id'];
if($delete_inbox = mysqli_prepare($conn, "DELETE FROM user_inbox where user_inbox_user=? AND user_inbox_status = 'trash'")){
mysqli_stmt_bind_param($delete_inbox, 'i', $userid);
mysqli_stmt_execute($delete_inbox);
mysqli_stmt_close($delete_inbox);
// Send response message if the operation was successful
$response['title'] = 'Messages deleted!';
$response['message'] = 'All messages have been deleted successfully.';
$response['status'] = 'success';
}else{
// Send response message if the operation failed
$response['title'] = 'An error occurred!';
$response['message'] = 'Unable to delete messages. Please contact system administrator';
$response['status'] = 'error';
}
echo json_encode($response);
}