3
I am making a simple form to be sent with jQuery Ajax. Data is being sent, but is updating the normal page.
I would like to know what I am doing wrong, because when sending the form the page is being updated, but I wish that did not occur.
Follows 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>
Alter your
.submit(function(){...
for.submit(function(e){...
and add right at the beginning of Functione.preventDefault();
before$(".listamensagem")...
, I think it solves– Augusto