Search code examples
javascriptphpjsonmailchimpmailchimp-api-v3.0

JSON showing error with MailChimp signup form


I'm trying to make a basic MailChimp signup form by using their API. I got a easy way from stackoverflow answer and I was follow code same to same. Hope everything is ok but when trying to submit form then data not sending. I saw a JSON error by inspect element.

Here the stackoverflow answer link: Create a basic MailChimp signup form using their API

Here the JSON error message get by console:

Uncaught SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.n.parseJSON (jquery-2.2.4.min.js:4)
    at Object.success (index.html?fname=AB&lname=Stevens&email=absiddiknmh%40gmail.com&submit=Submit:23)
    at i (jquery-2.2.4.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-2.2.4.min.js:2)
    at z (jquery-2.2.4.min.js:4)
    at XMLHttpRequest.<anonymous> (jquery-2.2.4.min.js:4)
n.parseJSON @ jquery-2.2.4.min.js:4
success @ index.html?fname=AB&lname=Stevens&email=absiddiknmh%40gmail.com&submit=Submit:23
i @ jquery-2.2.4.min.js:2
fireWith @ jquery-2.2.4.min.js:2
z @ jquery-2.2.4.min.js:4
(anonymous) @ jquery-2.2.4.min.js:4

Please anyone can give me idea why showing this error ?


Solution

  • I guess that you are using a wrong url. The url should be

    const url = https://us5.api.mailchimp.com/3.0/lists/${AUDIENCE_ID};

    You might have skipped ".api" in the url and wrote it like this

    const url = https://us5.mailchimp.com/3.0/lists/${AUDIENCE_ID};