Tuesday, 29 November, 2016 UTC


Summary

I’ll say it again. I love jQuery. There will never be a replacement.
Below is a cool little snippet I made to transform your MailChimp sign up form to an AJAX enabled one. One of the advantages being – you’re able to set your own redirect or set of actions afterwards. Also, no nasty popups:
<script>
jQuery("#mc-embedded-subscribe-form").submit(function(e) {

    var url = jQuery(this).prop('action'); // the script where you handle the form input.
    jQuery.ajax({
           type: "GET",
           url: url,
           data: jQuery("#mc-embedded-subscribe-form").serialize(), // serializes the form's elements.
           dataType: "jsonp",
           success: function(data)
           {
                if(data.result == 'success') window.location.href = 'https://example.franciskim.co/thank-you.html';
           }
         });

    e.preventDefault(); // avoid to execute the actual submit of the form.
});
</script>
Obviously, change the thank-you.html page to your liking but that should in theory work itself out.
Have fun! Peace!
The post How to Turn Your MailChimp Subscribe to AJAX (jQuery) appeared first on Francis Kim.