Last active
July 20, 2016 15:51
-
-
Save ultim8k/c765d7cc6d43803ecf4fff5159548665 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$.ajaxSetup({crossDomain : true}); | |
var url = 'https://your-url-is-here.com'; | |
var handleSuccess = function(resp) { | |
$('.loader').hide(); | |
$('.email_input').val(''); | |
$('.thanks').show(); | |
}; | |
var handleError = function(resp) { | |
$('.loader').hide(); | |
$('.error').show(); | |
}; | |
var submitSubscription = function() { | |
var emailRE = /.+\@.+\..+/; | |
var email = $('.email_input').val(); | |
var isEmailValid = emailRE.test(email); | |
if (!email || !isEmailValid) { return false; } | |
$('.loader').show(); | |
var willSubmit = $.post(url, {email: email}); | |
willSubmit.done(handleSuccess); | |
willSubmit.fail(handleError); | |
}; | |
$('.sign_up_button').click(function(e) { | |
submitSubscription(e); | |
}); | |
$('.email_input').on('keyup', function(e) { | |
$('.error').hide(); | |
if (e && e.keyCode === 13) { | |
submitSubscription(e); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment