Created
November 19, 2013 14:55
-
-
Save bkmorse/7546549 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| $(document).ready(function() | |
| { | |
| function displayAjaxMessage(message) | |
| { | |
| $("#newsletter-form-message").html(message); | |
| $("#newsletter-form-message").show(); | |
| } | |
| $("#newsletter-form").submit(function(event) | |
| { | |
| // stop the contact form from submitting normally | |
| event.preventDefault(); | |
| // hide any left over message from a previous submit | |
| $("#newsletter-form-message").hide(); | |
| $.ajax( | |
| { | |
| url: "/", | |
| type: "post", | |
| dataType: "html", | |
| data: $(this).serialize(), | |
| // there was an error | |
| error: function(jqXHR, textStatus, errorThrown) | |
| { | |
| displayAjaxMessage("Sorry, there was an error joining the list, please try again."); | |
| }, | |
| success: function(html, textStatus, jqXHR) | |
| { | |
| // displayAjaxMessage(html); | |
| if (html.match(/<title>Error<\/title>/)) | |
| { | |
| var error = $(html).find('ul li:first').text(); | |
| if (error == "Your email address is already in the mailing list") | |
| { | |
| displayAjaxMessage("Your email address is already on the mailing list."); | |
| } | |
| else if (error == "Invalid email address") | |
| { | |
| displayAjaxMessage("Enter a valid email address."); | |
| } | |
| else if (error == "You must submit an email address") | |
| { | |
| displayAjaxMessage("You must submit an email address."); | |
| } | |
| } | |
| else | |
| { | |
| $("#newsletter-form").hide(); | |
| displayAjaxMessage("Thanks! You should receive a confirmation email!"); | |
| } | |
| } | |
| }); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment