Skip to content

Instantly share code, notes, and snippets.

@ultim8k
Last active July 20, 2016 15:51
Show Gist options
  • Save ultim8k/c765d7cc6d43803ecf4fff5159548665 to your computer and use it in GitHub Desktop.
Save ultim8k/c765d7cc6d43803ecf4fff5159548665 to your computer and use it in GitHub Desktop.
$.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