Mailchimp API V3 jQuery Ajax POST订阅者

前端之家收集整理的这篇文章主要介绍了Mailchimp API V3 jQuery Ajax POST订阅者前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Mailchimp API(v3.0)有一个很大的更新,许多jQuery插件已经过时,以便在form.submit()上发布POST订阅者.

阅读v3.0文档后:

Managing subscribers建议使用以下JSON对象格式:

{
   "email_address": "urist.mcvankab@freddiesjokes.com","status": "subscribed","merge_fields": {
      "FNAME": "Urist","LNAME": "McVankab"
   }
}

以下API的根端点列出了资源:

HTTPS://< DC> .api.mailchimp.com / 3.0 /

所以这是我的form.submit()代码与jQuery Ajax POST请求:

$(document).ready(function(){
    var mcForm = $('#mailchimpForm');
    var mailchimp = {};
    mailchimp.dc='us5';
    mailchimp.id='xxxxxxxx';
    var url = '//' + mailchimp.dc + '.api.mailchimp.com/3.0/lists/' + mailchimp.id + '/members/';

    function beginMailchimpPost(data){
        var params = JSON.stringify(data);
        $.ajax({
            url: url,method: 'POST',data: params,dataType: 'jsonp',contentType: 'application/json; charset=utf-8',error: function(res,text){
                console.log('Err',res);
            },success: function(res){
                console.log('Success',res);
            }
        });
    }
});

这是JSON.stringify(数据)对象:

{"email_address":"email@mail.com","status":"subscribed","merge_fields":{"FNAME":"Name","LNAME":"Last name"}}

而且我收到以下错误

GET http://... 401 (Unauthorized)
Err Object {readyState: 4,status: 404,statusText: "error"}

可能有什么不对?

这是Mailchimp’s API v3.0 docs(列表成员集合)的链接.

解决方法

不幸的是,无法对前端Mailchimp API发出请求.

Note MailChimp does not support client-side implementation of our API
using CORS requests due to the potential security risk of exposing
account API keys.

https://developer.mailchimp.com/documentation/mailchimp/guides/get-started-with-mailchimp-api-3/#authentication

原文链接:https://www.f2er.com/jquery/178146.html

猜你在找的jQuery相关文章