Seriealize () Aajax with problem

0

I have several forms in an html, and I want to send with Ajax every form, I'm using serialize (). More is not working, where am I going wrong?

 <div class="resultado_<?php $i++; echo $i ?>">
  <span class="bom"><br>Cadastro Completo</span><br>

  <form method="post" id="favoritos" novalidate="novalidate">

      <input type="hidden" name="id_empresa" value="<?php echo $row["id"]?>" class="id_empresa">

   <input type="submit" value="Favoritos">



</form>
</div>

Ajax

$ (document) .ready (function () {     $ ("# favorites"). submit (function () {

    $.ajax({
        type: "POST",
        url: 'enviar_atualizar.php',
        data: $(this).serialize(),
        success: function (data) { 
            // Inserting html into the result div
            $('.resultado_'+formID).html(data);
        },
        error: function(jqXHR, text, error){
            // Displaying if there are any errors
            $('.resultado_'+formID).html(error);           
        }
    });
    return false;
});

});

returns this in the console

Uncaught ReferenceError: formID is not defined

    
asked by anonymous 02.05.2018 / 23:45

1 answer

0

Probably the variable formDetails was not declared or because it was not within $(document).ready(function() { ... }); it was not able to get the FORM, you can solve it simply by using:

$(document).ready(function() {
    $("#favoritos").submit(function() {

        $.ajax({
            type: "POST",
            url: 'enviar_atualizar.php',
            data: $(this).serialize(),
            success: function (data) { 
                // Inserting html into the result div
                $('.resultado_'+formID).html(data);
            },
            error: function(jqXHR, text, error){
                // Displaying if there are any errors
                $('.resultado_'+formID).html(error);           
            }
        });
        return false;
    });
});

The $(this) will refer to the element that received the submit event, in this case the <FORM> itself

    
02.05.2018 / 23:55