When using the confirm
method, it is essential to understand that it returns a boolean value indicating whether the prompt is confirmed. This allows you to store the boolean in a variable and verify if it is true before proceeding with the AJAX request.
$('.report').click(function() {
var id = $(this).data("id");
var confirmed = confirm("Are you sure you want to report this post?");
if (confirmed) {
$.ajax({
url: 'forumreport.php',
type: 'GET',
data: 'id='+id,
success: function(){
alert("Post has been reported successfully!");
},
});
}
});