Last active
August 29, 2015 14:20
-
-
Save sirtawast/34678d285f083e3fcb14 to your computer and use it in GitHub Desktop.
Simple AJAX form for MailChimp list subscriptions
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 id="mc-form" action="#" class=""> | |
<div id="mc-input-container"> | |
<input name="EMAIL" class="" type="email" placeholder="Your email" required> | |
<input id="mc-form-submit" class="mc-input-submit" type="submit" value="Submit"> | |
</div> | |
<div style="display: none;" id="mc-form-success" class=""> | |
Success! To finish your subscription go to your inbox and confirmation the confirmation message sent to you. | |
</div> | |
<div style="display: none;" id="mc-form-error" class=""> | |
Error! | |
</div> | |
</form> | |
<script> | |
// Requires jQuery | |
$(document).ready(function(){ | |
$('#mc-form').submit(function(e){ | |
e.preventDefault(); | |
$.ajax({ | |
url: '//{{mailchimplisturl}}/subscribe/post-json?u={{userid}}&id={{listid}}&c=?', | |
type: 'POST', | |
data: $(this).serialize(), | |
dataType: 'jsonp', | |
success: function(data) { | |
console.log (data); | |
if (data.result == "success") { | |
$('#mc-input-container').fadeOut(); | |
$('#mc-form-error').fadeOut(); | |
$('#mc-form-success').fadeIn(); | |
} | |
else { | |
$('#mc-form-error')[0].innerHTML = data.msg; | |
$('#mc-form-error').fadeIn(); | |
} | |
} | |
}) | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment