Delete log from the Modal Bootstrap window

2

I'm trying to delete a record from the Bootstrap modal window, but it's not working.

Look how I did it:

When you click the delete button for 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 page "deletar_formacao.php" reads the code through the post method and excludes the registry.

I have detected that it is as if the modal window and the onclick event of the delete class were competing. Could you give me some help?

    
asked by anonymous 29.06.2016 / 18:46

2 answers

1

Do as follows:

<a class="btn btn-primary delete" id="<?php echo $codigoform;?>">Apagar experiência</a>

Please note that I removed the modal call via the button.

And by jquery, you normally call it.

var id = $(this).attr('id');
            var data = 'id=' + id ;
$('#confirm-delete').modal('show'); 

        $("#confirm-delete").modal().find(".btn-ok").on("click", function(){
...

Use this logic and see if it works.

    
01.07.2016 / 14:21
3
$("a.delete").click(function(){
    var $this = $(this);
    var id = $this.attr("id");
    var data = 'id=' + id ;
    var $meu_alerta = $("#confirm-delete");
    $meu_alerta.modal().find(".btn-ok").on("click", function(){
        // $.ajax[...]
    });
});

JSFiddle

    
29.06.2016 / 19:28