Form duplicate using ajax

0

Sirs, good afternoon! I have the form where I register my information perfectly. I use Ajax because I upload only one page content after registration, not all of it. It works normal, the problem is if I make a new registration, it duplicates what I'm inserting, as if I sent the form twice. Then if I make a third insert, it duplicates the insert the number of times it was inserted earlier. If I give F5 on the page, it works normal too. What can it be? Has anyone ever had anything like this?

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 hope, and thank you in advance!

    
asked by anonymous 24.08.2016 / 20:29

0 answers