JQuery AJAX POST not working with MailChimp

I have the following code that I use to send data to the MailChimp mailing list (API v3). Every time I remove type: POST from the function that it is trying to send data via GET, and it sends the data correctly (ok response in the MailChimp API control panel). When testing this in a browser (FF), I get a .part file with a "true" answer.

  $(function(){ $("a#test").click(function(e){ e.preventDefault() data = { "apikey" : "667378947", "id" : "90298590285", "email_address" : "test@getmoxied.net", "output" : "json" } $.ajax({ type: "POST", url: 'http://us2.api.mailchimp.com/1.3/?method=listSubscribe', data: data, success: function(data){ alert(data); }, error: function(){ alert("err"); } }) }); }); 

I pull my hair out on this, any insight is much appreciated.

Thanks in advance,

Jn

+9
json javascript jquery ajax mailchimp
Mar 04 2018-11-11T00:
source share
3 answers

The main problem is that jc commented on your original post - it just won't work due to problems with the same original policy. Firebug is not so loud about why the GET call fails, but why it does not return any data. If you look that with POST you will see that Firefox does not even ring. The Chrome js console, on the other hand, directly explains the same outcome to you.

In general, this is very good, if only for the reason that it prevents you from publicly publishing your account API, which is very bad. If the reason you didn’t dive right away is to read the large number of methods available in the API, and then realize that all you need to access them is the API key.

The correct way to do this is to return the POST data to your server, and then make a request from there. There are several fully built PHP examples (one using jquery, even), here .

+8
Mar 04 2018-11-11T00:
source share

There is an undocumented endpoint that uses JSONP to execute cross-domain ajax requests.

Just change the message? to 'post-json?' and add '& c =?' to the end of the standard URL to get the JSONP endpoint. This does not require the API key to be displayed on the client side or to create a view on the server side.

I wrote a jQuery plugin that uses this method, if useful at all

https://github.com/scdoshi/jquery-ajaxchimp

+12
May 04 '13 at 2:08
source share
 e.preventDefault(); data = { "apikey" : "667378947", "id" : "90298590285", "email_address" : "test@getmoxied.net", "output" : "json" }; 

May be? The semicolon is important. Hehe

-2
Mar 04 2018-11-11T00:
source share



All Articles