Mailchimp API(v3.0)已經有了一個重大更新,許多jQuery插件已過期,以便POST
訂戶form.submit()
。Mailchimp API V3 jQuery Ajax POST訂閱者
Managing subscribers提出了以下JSON對象格式:
{
"email_address": "[email protected]",
"status": "subscribed",
"merge_fields": {
"FNAME": "Urist",
"LNAME": "McVankab"
}
}
而下面的根端點的API列表資源:
https://<dc>.api.mailchimp.com/3.0/
閱讀V3.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(data)
對象:
{"email_address":"[email protected]","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(列表成員集合)的鏈接。
最好的是http://stackoverflow.com/a/21491824/1821607 –