Confirmation box pops up more than once using ajax
- by peter burg
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.