Delete button does not work

0

I have this code to register and delete registration by ajax, the button Sign up It works more when I click Delete, it returns

  

Ajax Submit Failed to delete guest

But you are deleting the bank already.

Can you tell me where the error is?

<form url="cadastra_convidado.php" method="post" id="reg-form_2" autocomplete="off" style="border:none;">
    <input type="text" name="nome" id="nome" value="" placeholder="Digite o Nome do Convidado"><br>
    <input type="text" name="email" id="email" value="" placeholder="Digite o email do Convidado">
    <button class="btn btn-primary">Adicionar convidado</button>
</form>

<form url="deletar_convidado.php" method="post" id="reg-form_3" autocomplete="off" style="border:none;">
    <input type="hidden" name="deletar_convidado" id="deletar_convidado" value="<?php echo $row_convidados['id']; ?>">
    <button class="btn btn-primary" style="margin-bottom:20px;width: 100%;" type="submit">Exlcluir</button>
</form>
<div id="form-content_2"></div>  

Javascript:

$(document).ready(function () {

    $('#reg-form_2').submit(function (e) {

        e.preventDefault();

        $.ajax({
            url: 'cadastra_convidado.php',
            type: 'POST',
            data: $(this).serialize()
        })
        .done(function (data) {
            $('#form-content_2').fadeOut('slow', function () {
                $('#form-content_2').fadeIn('slow').html(data);
            });
        })
        .fail(function () {
            alert('Ajax Submit Failed ...');
        });
    });


    $(document).on('click', '#reg-form_3', function (e) {

        e.preventDefault();

        $.ajax({
            url: 'deletar_convidado.php',
            type: 'POST',
            data: $(this).serialize()
        })
        .done(function (data) {
            $('#form-content_2').fadeOut('slow', function () {
                $('#form-content_2').fadeIn('slow').html(data);
            });
        })
        .fail(function () {
            alert('Ajax Submit Failed deletar convidado ...');
        });
    });

});
    
asked by anonymous 03.04.2017 / 09:20

1 answer

0

These are sending two POST's

Try to remove the POST made by form

The delete button changes the type of submit to button and assigns an id

Follow this w3schools example

In my case I use the Postman , google extension to test GET & amp; amp; amp; amp; amp; amp; POST, this extension might help you

    
03.04.2017 / 10:12