Created
February 11, 2018 21:00
-
-
Save simplyluke/26c184e5803a1c27d1473223ae99be7d to your computer and use it in GitHub Desktop.
Mailchimp Ajax subscribe
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
$('#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