Seriealize() Aajax with problem

Asked

Viewed 19 times

0

I have several forms in an html, and I want to send with Ajax each form, I am using serialize(). But it’s not working out where I’m 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 on the console

Uncaught Referenceerror: formID is not defined

1 answer

0

Probably the variable formDetails has not been declared or is not within $(document).ready(function() { ... }); it has failed to catch the FORM, you can solve 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 event submit, in the event itself <FORM>

  • edited my reply, is returning an error on the console

  • @Wagnermartinsbodyboard formID was not defined, where should this var come from? Give details.

Browser other questions tagged

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