0
Speak personal, I have a table with several users, each row 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);
}
}
});
});
By clicking on button btn-delete
, I present a modal with two anchors, one with the confirmed removal, in case (#btn-true
), and one to cancel(#cancelar
) and closes the modal.
When I click on #btn-true
he quietly sends my request, but when I go on a second record, he sends 2 requests, the first and the second, and appears to me 2 notifications, I solved this problem with the stopImmediatePropagation();
, however, the element.remove()
; stop working, is there any way I can restart this event, so it doesn’t repeat with the same data from the previous event? Someone give a help?
Mayor, it worked!!! I had to put the element variable out of the function too.
– JASL
Excellent :), that good q worked
– Marcos Brinner