Reputation: 23
I wrote the following jQuery code (Ajax sending of mailchimp):
function formAjaxSending() {
var form = $('.block_main-footer__form');
form.submit(function (e) {
e.preventDefault();
$.ajax({
url: 'http://linkedin.us13.list-manage.com/subscribe?u=xxxxxxxxxxxxxxxxxxxxx&id=xxxxxxxxxxxxxxxxxxxxxxxxx',
type: 'GET',
crossDomain: true,
data: form.serialize(),
dataType: 'jsonp',
contentType: "application/jsonp; charset=utf-8",
success: function (data) {
if (data['result'] != "success") {
alert('error');
}
else {
alert('success')
}
}
});
});
}
formAjaxSending();
But it produces the following error with the jQuery plugin AJAXChimp:
Uncaught SyntaxError: Unexpected token <
With this error, I also see this link:
http://linkedin.us13.list-manage.com/subscribe?u=xxxxxxxxxxxx&id=xxxxxxxxx&callback=jQuery22407884056930053507_1469228177975&email=xxxxxxxxxxxxxxxx0gmail.com&_=1469228177976
I don't have any server-side code, so I can't elaborate more on that. Can anyone help me with solving this problem?
Upvotes: 1
Views: 1289
Reputation: 196
If you're going to submit the form client-side, you'll need to alter the form action and method.
In the action, instead of "/post", you'll need to change it to "/post-json".
Before: http://yourid.us12.list-manage.com/subscribe/post?xxx
After: http://yourid.us12.list-manage.com/subscribe/post-json?xxx
And also change the "post" method to "get".
Upvotes: 1
Reputation: 177
Had the same problem just today.
I couldn't find a solution so I changed approach.
Go to Mailchimp -> List -> Signup Forms
and create a Embedded Form.
Copy/Paste on your HTML (emit everything but the form content)
Now download AjaxChimp and follow readme.md
in your JS insert
$('#mc-embedded-subscribe-form').ajaxChimp({
url: 'http://yourid.us12.list-manage.com/subscribe/post?u=90d7ecc6fadf95bf8c79xxxx&id=e2c1f57xxxx'
//callback: callbackFunction
});
You can find the url in form action=""
Works for me.
Upvotes: 2