forked from BitBagCommerce/SyliusMailChimpPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbitbag-mailchimp-plugin-newsletter.js
41 lines (35 loc) · 1.39 KB
/
bitbag-mailchimp-plugin-newsletter.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
(function ($) {
'use strict';
$.fn.extend({
joinNewsletter: function () {
var form = $(this);
form.submit(function (event) {
event.preventDefault();
var successElement = form.find('.success-element');
var validationElement = form.find('.validation-element');
successElement.text('');
validationElement.text('');
$.ajax({
url: $(form).attr('action'),
type: $(form).attr('method'),
data: form.serialize()
})
.done(function (response) {
if (response.hasOwnProperty('message')) {
successElement.html(response.message);
}
})
.fail(function (response) {
if (response.responseJSON.hasOwnProperty('errors')) {
var errors = $.parseJSON(response.responseJSON.errors);
var message = '';
$(errors).each(function (key, value) {
message += value + " ";
});
validationElement.text(message);
}
});
});
}
});
})(jQuery);