栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

AJAX Mailchimp注册表单集成

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

AJAX Mailchimp注册表单集成

您不需要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... }        }    });}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/451943.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号