2
I’m trying to delete a record from the Bootstrap modal window, but it’s not working.
Look how I did:
By clicking the delete button of a particular record
<a class="btn btn-primary delete" href="#" data-href="#" data-target="#confirm-delete" data-toggle="modal" id="<?php echo $codigoform;?>">Apagar experiência</a>
jQuery interprets the command:
$('a.delete').click(function() {
var id = $(this).attr('id');
var data = 'id=' + id ;
var parent = $(this).parent().parent().parent().parent();
var $meu_alerta = $("#confirm-delete");
$meu_alerta.modal().find(".btn-ok").on("click", function() {
$.ajax({
type: "POST",
url: "deletar_formacao.php",
data: data,
cache: false,
success: function() {
parent.fadeOut('slow', function() {$(this).remove();});
window.location.reload();
}
});
});
});
The "deletar_formacao.php" page reads the code through the post method and deletes the record.
I detected that it’s as if the modal window and the onclick event of the delete class were competing. Could you give me a hand?
With
var id = this.id;
save one line and use less jQuery.– Sergio
Hello, Sergio and William. Please see above my edited code. Where I’m going wrong?
– Eduardo
When I run the code, the modal window opens and closes at the same time. I checked that if I hide the line -> var $meu_alerta = $("#confirm-delete") the modal appears, however, I cannot delete it.
– Eduardo
I thought that alone the show was triggered by the function
modal
, then try with$meu_alerta.modal('show')
to see if firm– William Novak
also unsuccessful :/
– Eduardo
puts in front of the
$('a.delete')
oneunbind('click')
staying that way$('a.delete').unbind('click').click(
can sometimes be due to any inconsistency in the rest of the code or by the HTML structure itself that makes the button "clicked" twice and can cause this "appears" and "disappears", keep trying, that an hour works– William Novak
also nothing :/
– Eduardo