您不需要API密钥,只需将标准mailchimp生成的表单放入代码中(根据需要自定义外观),然后将表单的“
action”属性更改
post?u=为
post-json?u=,然后在表单末尾进行操作附加
&c=?以解决任何跨域问题。同样重要的是要注意,提交表单时必须使用GET而不是POST。
默认情况下,您的表单标签如下所示:
<form action="http://xxxxx.us#.list-manage1.com/subscribe/post?u=xxxxx&id=xxxx" method="post" ... >
改变它看起来像这样
<form action="http://xxxxx.us#.list-manage1.com/subscribe/post-json?u=xxxxx&id=xxxx&c=?" method="get" ... >
Mail Chimp将返回一个包含2个值的json对象:’result’-这将指示请求是否成功(我只见过2个值,“error”和“success”)和’msg’-一条消息描述结果。
我使用以下jQuery提交表单:
$(document).ready( function () { // I only have one form on the page but you can be more specific if need be. var $form = $('form'); if ( $form.length > 0 ) { $('form input[type="submit"]').bind('click', function ( event ) { if ( event ) event.preventDefault(); // validate_input() is a validation function I wrote, you'll have to substitute this with your own. if ( validate_input($form) ) { register($form); } }); }});function register($form) { $.ajax({ type: $form.attr('method'), url: $form.attr('action'), data: $form.serialize(), cache : false, dataType : 'json', contentType: "application/json; charset=utf-8", error : function(err) { alert("Could not connect to the registration server. Please try again later."); }, success : function(data) { if (data.result != "success") { // Something went wrong, do something to notify the user. maybe alert(data.msg); } else { // It worked, carry on... } } });}


