Is there a way not to redirect people to a “thank you” page with Mailchimp?

人走茶凉 提交于 2019-12-09 23:29:11

问题


I saw on the Mailchimp website that you can redirect the user to a custom thank you page when they subscribe to your mailing list, but that's not exactly what I want to do.

When a user subscribe to my mailing list, I want to hide the form and replace it with a thank you note directly on my page without any redirection. Is there a way to do that?


回答1:


You can do this by modifying the form action.

Change “subscribe/post” to “subscribe/post-json” …

<form action="...list-manage.com/subscribe/post-json?u=...."

Add a submit handler to the form:

$("#subscribe-form").submit(function(e){
    e.preventDefault();
    submitSubscribeForm($("#subscribe-form"));
});

Submit the form via AJAX (Code referenced from Github here):

function submitSubscribeForm($form, $resultElement) {
        $.ajax({
            type: "GET",
            url: $form.attr("action"),
            data: $form.serialize(),
            cache: false,
            dataType: "jsonp",
            jsonp: "c",
            contentType: "application/json; charset=utf-8",

            error: function(error){},

            success: function(data){
                if (data.result != "success") {
                    var message = data.msg || "Sorry. Unable to subscribe. Please try again later.";

                    if (data.msg && data.msg.indexOf("already subscribed") >= 0) {
                        message = "You're already subscribed. Thank you.";
                    }

                    $resultElement.html(message);

                } else {

And then write the code to display the signup confirmation

                    $resultElement.html("Thank you!<br>You must confirm the subscription in your inbox.");
                }
            }
        });
    }


来源:https://stackoverflow.com/questions/23834631/is-there-a-way-not-to-redirect-people-to-a-thank-you-page-with-mailchimp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!