I'm making a simple form to be submitted with jQuery Ajax. Data is being sent, but you are updating the normal page.
I would like to know what I am doing wrong, because in submitting the form the page is being updated, but I would like this not to happen.
Follow the codes:
Ajax:
$(document).ready(function() {
$(".enviamensagem").submit(function (){
$(".listamensagem").html("<h4>Carregando Mensagens</h4>");
var formdata = $(".enviamensagem").serialize();
$.ajax({
type:"POST",
url:"dados.php",
data: formdata,
beforeSend: function(){
},
success:function(data){
$("#areamsg").html(data);
}
});
});
});
HTML:
<form method="post" class="enviamensagem">
<fieldset>
<label >Escrever Mensagem:
<textarea name="mensagem" required></textarea></label>
<input type="submit" class="botao" id="btnenviamsg" value="Enviar" />
</fieldset>
</form>