-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewsletter-ajax.js
42 lines (33 loc) · 1.13 KB
/
newsletter-ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
jQuery(function($) {
$('.tmcajax').on('submit',function(e) {
currentForm = $(this)
e.preventDefault();
$('.tmcajax .fa-circle-o-notch').css({'display': 'inline-block'})
$('.tmcajaxresponse').hide()
var formData = $(this).serialize();
$.ajax({
method: 'POST',
url: tommy_plugin_path['template_url'] + 'mc-endpoint.php',
data: formData,
dataType: 'json'
}).success(function(data){
$('.tmcajax .fa-circle-o-notch').css({'display': 'none'})
if ( data.title == 'Member Exists') {
currentForm.find('.tmcajaxresponse.welcome').show()
}
else if(data.id){
if(currentForm.hasClass('pending')){
currentForm.find('.tmcajaxresponse.opt-in').show()
} else if(currentForm.hasClass('subscribed')) {
currentForm.find('.tmcajaxresponse.welcome').show()
}
} else {
currentForm.find('.tmcajaxresponse.error').show()
}
}).error(function(error){
currentForm.find('.tmcajaxresponse').hide()
$('.tmcajax .fa-circle-o-notch').css({'display': 'none'})
currentForm.find('.tmcajaxresponse.error').show()
});
});
});