简体   繁体   中英

Mailchimp AJAX jQuery Unexpected token <

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?

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&amp;id=e2c1f57xxxx'
  //callback: callbackFunction
});

You can find the url in form action=""

Works for me.

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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM