mikesallander
10/22/2016 - 4:52 PM

Constant Contact Ajax Form

Constant Contact Ajax Form

$(".footer-signup__form").submit(function(event) {
  var $form = $(this);
  $.ajax({
    type: 'POST', // HTTP method, always use POST for our form
    url: 'https://visitor2.constantcontact.com/api/signup',
    data: $form.serialize(), // serialized form data
    dataType: 'json', // the type of data we expect back from the server
    success: function() {
      $form.fadeOut(250, function() {
        $(".footer-signup__alert").addClass("footer-signup__alert--success").html('<p>You have been added to our list!</p>').fadeIn(250);
      });
    },
    error: function(response) {
      $form.fadeOut(250, function() {
        $(".footer-signup__alert").addClass("footer-signup__alert--danger").html('<p>' + response.responseJSON.err + '. Please contact us for assistance</p>').fadeIn(250);
      });
    }
  });
  // stop the form from submitting the normal way and refreshing the page
  event.preventDefault();
});
<div class="footer-signup__alert"></div>
<form  class="footer-signup__form" action=" ">
  <input type="hidden" name="ca" value="22a425e5-8c33-4258-8926-5eac0b2ccc4a">
  <input type="hidden" name="list" value="1065413952">
  <input name="email" type="email" required="required" placeholder="Your Email*">
  <button type="submit" class="reset">Subscribe</button>
</form>