Created
June 25, 2014 20:48
-
-
Save strukturedkaos/a218acb56f4759ca7bb2 to your computer and use it in GitHub Desktop.
Angular Mailchimp Controller's POST request to Mailchimp API
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
// Send subscriber data to MailChimp | |
MailChimpSubscription.save( | |
// Successfully sent data to MailChimp. | |
function (response) { | |
// Define message containers. | |
mailchimp.successMessage = ''; | |
mailchimp.errorMessage = ''; | |
// Store the result from MailChimp | |
mailchimp.result = response.result; | |
// Mailchimp returned an error. | |
if (response.result === 'error') { | |
if (response.msg) { | |
// Remove error numbers, if any. | |
var errorMessageParts = response.msg.split(' - '); | |
if (errorMessageParts.length > 1) | |
errorMessageParts.shift(); // Remove the error number | |
mailchimp.errorMessage = errorMessageParts.join(' '); | |
} else { | |
mailchimp.errorMessage = 'Sorry! An unknown error occured.'; | |
} | |
} | |
// MailChimp returns a success. | |
else if (response.result === 'success') { | |
mailchimp.successMessage = "Thanks for subscribing! Please confirm the email you receive to complete the process."; | |
} | |
}, | |
// Error sending data to MailChimp | |
function (error) { | |
$log.error('MailChimp Error: %o', error); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment