Skip to content

Instantly share code, notes, and snippets.

@crismanNoble crismanNoble/mc-submit.js

Last active Sep 29, 2015
What would you like to do?
Simple form AJAX example
//prevent the form from submitting via the browser redirect
//grab attributes and values out of the form
var data = {email: $('#mc-email').val()};
var endpoint = $(this).attr('action');
//make the ajax request
method: 'POST',
dataType: "json",
url: endpoint,
data: data
//successful adds will have an id attribute on the object
alert('thanks for signing up');
} else if (data.title == 'Member Exists') {
//MC wil send back an error object with "Member Exists" as the title
alert('thanks, but you are alredy signed up');
} else {
//something went wrong with the API call
alert('oh no, there has been a problem');
//the AJAX function returned a non-200, probably a server problem
alert('oh no, there has been a problem');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.