Last active
December 27, 2015 16:19
-
-
Save origamid/7354156 to your computer and use it in GitHub Desktop.
JS: Ajax Form
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
$('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