I am trying to make an ajax call to remove a user using the autoload mod. The modal is used to confirm, and it is next.
<div id="deleteModal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h3 id="myModalLabel">Delete user</h3> </div> <div class="modal-body"> <p>You are about to delete this user. Are you sure that you want to continue?</p> </div> <div class="modal-footer"> <button id="confirm" class="btn btn-primary">Yes</button> <button id="cancel" class="btn" data-dismiss="modal" aria-hidden="true">No, leave</button> </div> </div>
Then I use the following javascript to handle user input
$('a#delete').click(function(e){ var anchor = this; $('#deleteModal').modal('show'); $('button#confirm').click(function(e){ $('#deleteModal').modal('hide'); $.ajax({ url: $(anchor).attr('href'), success:function(result){ $(anchor).closest('tr').addClass("error"); $(anchor).closest('tr').delay(2000).fadeOut(); }}); }); return false; });
The link that the user needs to click looks like this
<a id="delete" href="/admin/edit/user/delete/30" class="btn btn-danger" user="30"><i class="icon-trash"></i> Delete</a>
This works, but I noticed something strange was happening. If I click to delete one user, and I decided to cancel the action from the modal, and then I decided to delete another user who confirms the action, both users will be deleted.
I think the rule that I declared still applies to objects that were clicked during the session. Is there any way to avoid this?
source share