Skip to content

Instantly share code, notes, and snippets.

@origamid
Last active December 27, 2015 16:19
Show Gist options
  • Save origamid/7354156 to your computer and use it in GitHub Desktop.
Save origamid/7354156 to your computer and use it in GitHub Desktop.
JS: Ajax Form
$('form.contato__form').on('submit', function() {
var that = $(this),
url = that.attr('action'),
type = that.attr('method'),
data = {};
that.find('[name]').each(function(index, value) {
var that = $(this),
name = that.attr('name'),
value = that.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response) {
$('.contato__form').html("<div id='message'></div>");
$('#message').html("<span>Enviou certinho!</span><p>Em no máximo 24h eu entro em contato com você.</p> <span>Abraços!</span>")
.hide()
.fadeIn(1500, function() {
$('#message');
});
},
error: function(response) {
$('.contato__form').html("<div id='message'></div>");
$('#message').html("<span>Alguma coisa deu errada!</span><p>Você pode tentar novamente, ou enviar direto para o e-mail [email protected].</p>")
.hide()
.fadeIn(1500, function() {
$('#message');
});
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment