1
After changing the code, I left this way but I analyzed the browser console and realized that the Submit button still not calling the function:
<div class="container">
<div class="spacer">
<div class="row contact">
<div class="col-lg-6 col-sm-6 ">
<form id="form-ajax">
<input type="text" class="form-control" placeholder="Nome completo:" id="nome">
<input type="text" class="form-control" placeholder="E-mail:" id="email">
<input type="text" class="form-control" placeholder="Número para contato:" id="num">
<textarea rows="6" class="form-control" placeholder="Digite sua mensagem" id="msg"></textarea>
<input type="button" class="btn btn-success" id="enviar" value="Enviar">
</form>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('#form-ajax').click(function(e){
e.preventDefault();
alert('entrou na função');
if($('#enviar').val() === 'Enviando...'){
return(false);
}
$('#enviar').val('Enviando...');
$.ajax({
url: 'phpmailer.php',
type: 'post',
dataType: 'json',
data: {
'nome':$('#nome').val(),
'email':$('#email').val(),
'num':$('#num').val(),
'msg':$('#msg').val()
}
}).done(function(data){
alert(data);
$('#nome').val();
$('#email').val();
$('#num').val();
$('#msg').val();
});
});
});
</script>
Have you tried calling the function on the button?
– Xeoon