Created
March 2, 2016 02:53
-
-
Save code26/9575c8c0626e22fe296a to your computer and use it in GitHub Desktop.
mailchimp js
This file contains 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
var app = (function(){ | |
return { | |
events: function() { | |
//form | |
var $form = $('#subscribeForm'), | |
$formContainer = $('.form-container'), | |
$notify = $('.error-msg',$formContainer); | |
if ( $form.length > 0 ) { | |
$form.on('submit',function(e){ | |
e.preventDefault(); | |
$('.btn-submit',$form).trigger('click'); | |
}) | |
$form.on('click', '.btn-goback', function(e){ | |
e.preventDefault(); | |
$formContainer.removeClass('error'); | |
}); | |
$('.btn-submit',$form).on('click', function ( e ) { | |
e.preventDefault(); | |
$notify.html(''); | |
function cb_success() { | |
$formContainer.addClass('success'); | |
//$title.html('Check your e-mail!'); | |
//$notify.html('We’ve sent you a confirmation letter for a free Joomajam lesson at your e-mail address!'); | |
} | |
function cb_failed(data) { | |
$formContainer.addClass('error'); | |
$notify.html('We\'ve encountered the following error(s):<br>').append(data); | |
} | |
function cb_error(err) { | |
//console.log(err); | |
$formContainer.addClass('error'); | |
$notify.html('').append('Sorry. We could not connect to the registration server. Please try again later.'); | |
} | |
app.mailchimp($form,cb_success,cb_failed,cb_error); | |
}); | |
} | |
return this; | |
}, | |
mailchimp: function($form,cb_success,cb_failed,cb_error) { | |
$.ajax({ | |
type: $form.attr('method'), | |
url: $form.attr('action'), | |
data: $form.serialize(), | |
cache : false, | |
dataType : 'json', | |
contentType: "application/json; charset=utf-8", | |
error : function() { | |
//alert("Could not connect to the registration server. Please try again later."); | |
cb_error(); | |
}, | |
success : function(data) { | |
if (data.result != "success") { | |
cb_failed(data.msg); | |
//cb_success(); | |
} else { | |
cb_success(); | |
} | |
} | |
}); | |
}, | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment