How to use jQuery Ajax with Mailchimp API 2.0 (not PHP)

730 views
Skip to first unread message

Calebe Garcia

unread,
Feb 18, 2014, 7:02:50 AM2/18/14
to mailchimp-...@googlegroups.com
Trying to create an simple dashboard to post an campaign. Is it possible to do that just with AJAX, (not PHP



<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Mail</title>

</head>
<body>
<a href="#">Send</a>
<script>
    $(function(){
       $("a").click(function(e){
         e.preventDefault()  
         data =
 
 
 {
     "apikey": "999999999999999-us7",
     "type": "auto",
     "options": {
         "list_id": "999999999",
         "subject": "Teste 1",
         "from_email": "b...@exemple.com",
         "from_name": "From Carl",
         "to_name": "Cal",
         "tracking": {
             "opens": true,
             "html_clicks": true,
             "text_clicks": true
         },
         "title": "Test",
         "authenticate": true,
         "auto_footer": true,
         "inline_css": true,
         "generate_text": true,
     "content": {
         "html": "example html"
     }
     }
 }
 
 
 
 

    $.ajax({ 
      type: "POST",
      data: data,
      cache       : false,
      dataType    : 'json',
      contentType: "application/json; charset=utf-8",
      success: function(data){
        console.log(data);
      },
      error: function(){
       console.log(data);
      }
    })       
   });
  }); 
  
  
  
</script>
</body>
</html>


Colt

unread,
Feb 18, 2014, 3:41:53 PM2/18/14
to mailchimp-...@googlegroups.com
Hey Calebe!

When you're using AJAX you're not going to want to post that information directly to the MailChimp API itself. 

What you can do for example though, is have that post to your own local script such as a PHP file, then have that PHP file communicate with the MailChimp API and return the data you'd like.
Reply all
Reply to author
Forward
0 new messages