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