JQuery and Ajax confirmation box
I need help with this. I have a function that works well with ajax, but I need a delete confirmation / cancellation confirmation before I send an ajax request to delete an item from the database. This is my code:
delete_article = function(article_id){
$.ajax({
type:"POST",
url: "<?php echo base_url()?>admin/article/delete_article",
data: "article_id="+article_id,
asynchronous: true,
cache: false,
beforeSend: function(){
},
success: function(){
$('#articletr'+article_id).hide();
}
});
}
})
+3
source to share
2 answers
var answer = confirm ("Are you sure you want to delete from the database?");
if (answer)
{
// your ajax code
}
If you need more control over these modal dialogs with jQuery (buttons that say something other than OK / cancel, more than two buttons, or different styles), you can use the Modified JQuery UI Confirmation .
+9
source to share
The easiest way is to use the inline javascript method confirm
:
if (confirm("Really send?")) {
// Do it!
}
Because these built-in browser dialogs have a very ugly history and cannot be styled at all, they are often avoided in favor of other methods. JQuery UI Dialog Widget is good examples
+2
source to share