Duplicate form using ajax

Asked

Viewed 78 times

0

Gentlemen, good afternoon to you! I have the form where I register my information perfectly. I use Ajax pq I only upload one page content after registration, and not all of it. It works normally, the problem is if I go to make a new registration, it duplicates what I insert it, as if I sent the form twice. So if I go for a third insertion, it duplicates the insertion the amount of times it was previously inserted. If I give F5 on the page, it works normal too. What can it be? Someone has been through something similar?

The function I use to perform the insertion is this:

$(document).ready(function ()
{
    $(document).on('submit', '#form_nova_categoria', function ()
    {
        var data = $(this).serialize();

        $.ajax({
            type: 'POST',
            url: '../../../../acotacao/admin/cadastro/mercadologico/acoes/nova_categoria.php',
            data: data,
            success: function (data)
            {
                if (data === "ok") {


                    $("#collapse_nova_categoria").collapse('toggle');
                    $(".conteudo_pagina").hide();
                    $("#conteudo").load("../../../../acotacao/admin/cadastro/mercadologico/categorias.php").fadeIn("slow");
                    $("#msg-ok").fadeTo(2000, 500).slideUp(500, function () {
                        $("#msg-ok").slideUp(500);
                    });
                } else {
                    $("#collapse_nova_categoria").collapse('toggle');
                    $(".conteudo_pagina").hide();
                    $("#conteudo").load("../../../../acotacao/admin/cadastro/mercadologico/categorias.php").fadeIn("slow");
                    $("#msg-erro").fadeTo(2000, 500).slideUp(500, function () {
                        $("#msg-erro").slideUp(500);
                    });
                }
            },
            error: function () {
                $("#collapse_nova_categoria").collapse('toggle');
                $(".conteudo_pagina").hide();
                $("#conteudo").load("../../../../acotacao/admin/cadastro/mercadologico/categorias.php").fadeIn("slow");
                $("#msg-erro").fadeTo(2000, 500).slideUp(500, function () {
                    $("#msg-erro").slideUp(500);
                });
            }
        });
        return false;
    });
});

I await, and thank you in advance!

  • by chance the insert that this duplicating is that: $("#conteudo").load('...')?

  • Well, this line refers to reloading the div I want you to update. Like I said, I’m not giving refresh on the page, it inserts and updates the div showing the insertion that was made.

  • I just removed this line you mentioned @Neuberoliveira and the error persists.

  • "I only upload one page content after registering" what code snippet does this upload? How far do I realize the only thing that’s being loaded after Ubmit is with that $.load() also put the passage that is being duplicated, gives a little more context.

No answers

Browser other questions tagged

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