AJAX Mailchimp 注册表单集成 [英] AJAX Mailchimp signup form integration

查看:27
本文介绍了AJAX Mailchimp 注册表单集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以将 mailchimp simple(一个电子邮件输入)与 AJAX 集成,这样就没有页面刷新,也没有重定向到默认的 mailchimp 页面.

Is there any way to integrate mailchimp simple (one email input) with AJAX, so there is no page refresh and no redirection to default mailchimp page.

此解决方案不起作用 jQuery Ajax POST 不适用于 MailChimp

谢谢

推荐答案

您不需要 API 密钥,您所要做的就是将标准的 mailchimp 生成的表单放入您的代码中(根据需要自定义外观)并在表单action"属性将 post?u= 更改为 post-json?u= 然后在表单操作的末尾附加 &c=? 解决任何跨域问题.另外需要注意的是,当您提交表单时,您必须使用 GET 而不是 POST.

You don't need an API key, all you have to do is plop the standard mailchimp generated form into your code ( customize the look as needed ) and in the forms "action" attribute change post?u= to post-json?u= and then at the end of the forms action append &c=? to get around any cross domain issue. Also it's important to note that when you submit the form you must use GET rather than POST.

您的表单标签默认如下所示:

Your form tag will look something like this by default:

<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'- 描述结果的消息.

Mail Chimp will return a json object containing 2 values: 'result' - this will indicate if the request was successful or not ( I've only ever seen 2 values, "error" and "success" ) and 'msg' - a message describing the result.

我用这个 jQuery 来提交我的表单:

I submit my forms with this bit of 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...
            }
        }
    });
}

这篇关于AJAX Mailchimp 注册表单集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆