Skip to content

Instantly share code, notes, and snippets.

@simplyluke
Created February 11, 2018 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simplyluke/26c184e5803a1c27d1473223ae99be7d to your computer and use it in GitHub Desktop.
Save simplyluke/26c184e5803a1c27d1473223ae99be7d to your computer and use it in GitHub Desktop.
Mailchimp Ajax subscribe
$('#mc-embedded-subscribe-form').submit(function(e) {
e.preventDefault();
$('#loading_gif_mc').show();
$('#mc_embed_signup').hide();
$.ajax({
type: $('#mc-embedded-subscribe-form').attr('method'),
url: $('#mc-embedded-subscribe-form').attr('action'),
data: $('#mc-embedded-subscribe-form').serialize(),
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
error: function(err) {
$('#mc-embedded-subscribe-form').html("<h3>We're sorry, something went wrong</h3>");
$('#loading_gif_mc').hide();
$('#mc_embed_signup').show();
},
success: function (data) {
$('#loading_gif_mc').hide();
$('#mc_embed_signup').show();
if (data.result == "success") {
$('#mc-embedded-subscribe-form').html("<p>Thank you!</p>");
} else {
$('#mc-embedded-subscribe-form').html('<div class="text-danger">' + data.msg + '</div>');
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment