我的网站中嵌入了一个简单的Mailchimp表单(只是一个电子邮件输入和提交按钮),但我无法弄清楚如何在提交后停止自动Mailchimp成功页面的打开?是否有一个jQuery函数来处理这个?我想要一个简单的"谢谢你"提交后代替表单的消息。
这是我到目前为止所拥有的:
<div class="newsletter-module" id="mc_embed_signup">
<a href="#" class="news-show"><p>Join mailing list</p></a>
<!-- MC SIGNUP FORM -->
<form class="signup validate" action="mailchimp-link-here" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" onsubmit="return Validate()">
<span class="newsletter-input-wrapper mc-field-group">
<input class="input-text required email" id="mce-EMAIL" type="email" value="" name="EMAIL" placeholder="email address" required>
</span>
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input type="text" name="b_f2d244c0df42a0431bd08ddea_aeaa9dd034" tabindex="-1" value=""></div>
<div id="mce-responses" class="clear">
<div class="response" id="mce-error-response" style="display:none"></div>
<div class="response" id="mce-success-response" style="display:none"></div>
</div>
<label>
<input type="submit" name="subscribe" value="Sign Up" id="mc-embedded-subscribe" class="button">
</label>
<div id="success-msg"><p>Thank you!</p></div>
</form>
</div> <!-- .newsletter-module -->
的jQuery
$(".news-show").click(function(e){
e.preventDefault();
$(this).hide();
$(this).next(".signup").show();
});
$(function(){
$("#success-msg").hide();
$(".button").on("click", function(){
$("#success-msg").show();
});
});
答案 0 :(得分:0)
if (!$email[0].checkValidity()) {
return;
}
$email.prop('disabled', true);
$("input[type='submit']", $el).prop('disabled', true);
return $.ajax({
type: "GET",
url: $el.attr("action").replace('/post', '/post-json'),
data: data,
cache: false,
dataType: "jsonp",
jsonp: "c",
contentType: "application/json; charset=utf-8",
error: function(error) {},
success: function(data) {
if ((data.result === "success") ||
(data.msg && data.msg.indexOf("already subscribed") >= 0) ||
(data.msg && data.msg.indexOf("too many recent signup requests") >= 0)
) {
$el.html('thank you!');
setTimeout(function() {
$el.fadeOut(500);
}, 2000);
$(".news-show").delay(3000).fadeIn(500);
} else {
$email.prop('disabled', false);
("input[type='submit']", $el).prop('disabled', false);
}
}
});
});