Last active
January 26, 2018 18:31
-
-
Save thiagotmendes/ca2136f896fee5e0dac2e53ad22c4db1 to your computer and use it in GitHub Desktop.
jquery para disparo de formulario sem refresh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// inicia o jquery validate | |
$('#indicalivro').validate({ | |
// regras de validação | |
rules:{ | |
nome: "required", | |
email: { | |
required: true, | |
email: true | |
} | |
}, | |
// mensagens que deseja enviar ao usuario | |
messages: { | |
nome: "Preencha o nome por favor", | |
}, | |
// dispara o formulario | |
submitHandler:function(form){ | |
// var dadosForm = $(this).serialize(); | |
var fd = new FormData(); | |
fd.append("nome",$('#nome').val()); | |
fd.append("email",$('#email').val()); | |
fd.append("serie",$('#serie').val()); | |
fd.append("colegio",$('#colegio').val()); | |
fd.append("titulo_livro",$('#titulo_livro').val()); | |
fd.append("autor",$('#autor').val()); | |
fd.append("comentario",$('#comentario').val()); | |
// | |
fd.append( "capalivro", $('#capalivro')[0].files[0]); | |
fd.append( "action", 'makeBooking'); | |
// dispara o email | |
$.ajax({ | |
type : 'POST', | |
url : ADMajax.ajax_url, | |
processData: false, | |
contentType: false, | |
data: fd, | |
success: function( data ) | |
{ | |
$("#indicalivro").trigger("reset"); | |
$("#btnSubmit").before("<div id='alerta' class='alert alert-success text-center'> Livro indicado com sucesso! </div>"); | |
$("#alerta").fadeIn(5000).delay(3000).fadeOut(); | |
}, | |
error: function(MLHttpRequest, textStatus, errorThrown) { | |
console.log(errorThrown); | |
} | |
}); | |
return false; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment