I have a table with several users, each line has a Button to delete that particular record, I have the following code:
$('body').on('click', 'button[name="btn-delete[]"]', function (e) {
e.preventDefault();
var action = $(this).data("function");
var nameType = $(this).data("name");
var codigo = $(this).val();
var Name = $('.user-name-' + codigo).html();
var element = $(this).parent().parent().parent();
$('.header-modal-box h4').text('Deletar');
$('.row-f label').text('Deseja remover o ' + nameType + ' ' + Name + '?');
Modal();
$('#btn-true').click(function () {
if ($('.trigger_notify').length) {
$('.trigger_notify').remove();
}
$.ajax({
url: '_models/Data.php?action=' + action,
method: 'POST',
data: {codigo: codigo},
dataType: 'json',
success: function (data) {
if (data.erro === true) {
trigger(data.notify);
element.remove();
} else {
trigger(data.notify);
}
}
});
});
When I click on button btn-delete
, I present a modal with two anchor, one with the commit commit, in the case ( #btn-true
), and one to cancel ( #cancelar
) and closes the modal.
When I click on #btn-true
it sends my request quietly, but when I go in a second register, it sends 2 requests, the first and the second, and I get 2 notifications, I solved this problem with stopImmediatePropagation();
however, element.remove()
; to work, will be if I have to restart this event, so it does not repeat with the same data as the previous event? Is there anyone there to help?