我只是不明白为什么这个表单发送同一电子邮件的多个副本(从1-8个副本的任何地方)。我尽力解决问题,但我无法弄清楚。jQuery Ajax多次提交多次
我使用jQuery验证引擎来验证表单,如果正确验证,我用jquery.post()提交表单。
我包括我的所有代码,只是为了安全起见。但是有些东西可能并不重要,比如我在消息成功发送时加载到iframe中的ppcconversion脚本。
请参见下面的代码:
$(".consult-form form .submit").click(function(){
$(".consult-form form").validationEngine('attach', {
promptPosition : "topLeft",
onValidationComplete: function(contactForm, status){
if(status==true){
$(".consult-form form .submit").clone().insertAfter($(this)).attr("disabled","true");
$(".consult-form form .submit").hide();
_gaq.push(['_trackPageview', '/web-contact']); // Google Page Tracker
$.post('/path/to/process.php', $(".consult-form form").serialize(), function(data) {
// Add Thank You Message
$('.thank-you-message').html(data);
// Create IFRAME to page with Adwords Tracking Script
function ppcconversion() {
var iframe = document.createElement('iframe');
iframe.style.width = '0px';
iframe.style.height = '0px';
document.body.appendChild(iframe);
iframe.src = 'http://www.fullurlto.com/conversion-script.php';
};
ppcconversion();
});
return false; // I attempted to add this line to prevent it from submitting multiple times. It didn't work.
$(".consult-form form").hide();
}
}
});
});
如果有您需要更深入的了解只是让我知道的任何细节,我会为他们提供。
谢谢!
这很有道理。我明白你的建议,但我不确定如何相应地编辑我的代码。对不起,我不是很有经验。你能在你的答案中提供更详细的例子吗? – norsewulf
更换'$( “CONSULT-form表单.submit”)。点击(函数(){'和'$(函数(){' – Andreas
哦哈哈,没关系很容易的。我做了更新,我的代码。我认为这可能是问题,但我会在一些测试后将它作为正确的答案。谢谢! – norsewulf