Confirmation box pops up more than once using ajax

Posted by peter burg on Stack Overflow See other posts from Stack Overflow or by peter burg
Published on 2012-09-28T21:35:02Z Indexed on 2012/09/28 21:37 UTC
Read the original article Hit count: 225

Filed under:
|

I'm using Ajax to delete records and display an animated message (function display_message) when this record is deleted, but I noticed that the confirmation box pops up depending on the number of records. for example if I have 2 records in my list and I want to delete on of them.The confirmation box pops up twice before deleting and the same thing happen with the message, It appears twice(I'm using a message that fade in and out), and so on(3 records -> 3 pops up, etc). I tried a lot to resolve it but I haven't succeed . Here is my function that delete the records:

$(function() {
$(".delete_class").click(function() {
var id = $(this).attr("id");
var dataString = 'id='+ id ;
var parent = $(this).parent().parent();
if(confirm("are you sure?")) {
$.ajax({
type: "POST",
url: "delete.php",
data: dataString,
cache: false,
success: function()
{
parent.hide();
}
});
}
display_message("user deleted!")
}); 
});

Please help.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX