Delete button does not work

Asked

Viewed 53 times

0

I have this code to register and delete record by ajax, the Register button works more when I click Delete, returns

Ajax Submit Failed Delete Guest

But you’re ruling out the bank already.

Can you tell me where the mistake 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 ...');
        });
    });

});

1 answer

0

Sending two POST’S

Tries to remove the POST done by form

On the delete button changes the type of Submit to button and assigns an id

Follow this example from w3schools

In my case I use the Postman, google extension to test GET & POST requests, this extension can help you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.