1
I have a problem in a listing, is the following, I have a table, for each row has a link to be able to edit the line, with this, when clicking on this link opens a bootstrap modal with all its content coming via Ajax, and so far this is all right. And when I close the modal I call an event of it to be able to update the table line.
My problem is that you keep accumulating calls for this line update, for example: I have the first line, I will click the edit button, open the modal, and when I close this modal it updates me the data of the line clicked; when I click on another edit link (or even on it), open the modal and then when I close this modal it updates the data of the clicked line, only when looking at the console I see that it makes the first and the second call of the lines to be updated, I wonder what might be accumulating these calls that only happen when I close the modal?
It follows an idea of the code, what happens in this case is that every time you open the modal, when it closes it will be accumulating Alert
$('a.edit_row_dt').on('click', function(e) {
e.preventDefault();
var item_id = $(this).data('id');
var row = $(this).closest('tr');
$('#edit').load('edit.php', {"id" : item_id}, function(){
$('#edit').modal();
$('#edit').on('hidden.bs.modal', function(event) {
event.preventDefault();
alert(item_id); // aqui
$('.modal-dialog').remove();
});
}
);
});
I haven’t been able to visualize exactly what event the problem is occurring in. Ideally, the event should be "scheduled" only once, but if you need a different behavior, you can always "Clear" previous events with: http://api.jquery.com/unbind/ before adding another one.
– mau humor