Prevent AJAX form from submitting twice?

I can't figure out why this AJAX form is processing and sending out an email twice. Is there some sort of obvious hickup in the code you can see causing this to occur? HTML

By clicking Submit you agree to our Terms & Conditions

JavaScript processSubmitModal : function () { var form = $('.submit-form'), content_link = $('.submit-form input[type="url"]'), email = $('.submit-form input[type="email"]'), viewport_size = $(window).width() + "x" + $(window).height(), user_browser = BrowserDetect.browser, user_os = BrowserDetect.OS, current_page = document.location.href; $('.submit-form input[type="url"],.submit-form input[type="email"]').blur(function () { if ($.trim($(this).val()) == '') { $(this).addClass('form-validation-error'); return false; } else { $(this).removeClass('form-validation-error'); } }); form.submit(function () { if ($.trim(content_link.val()) == '' && $.trim(email.val()) == '') { content_link.addClass('form-validation-error'); email.addClass('form-validation-error'); return false; } else if ($.trim(content_link.val()) == '') { content_link.addClass('form-validation-error'); return false; } else if ($.trim(email.val()) == '') { email.addClass('form-validation-error'); return false; } else { var env = TTB.getEnvironment(); $('.submit-modal-button').attr('disabled','disabled'); $(document).ajaxStart(function () { $('.submit-modal .screen-1').delay(300).append(''); }); $.ajax({ url: env.submit_modal_process, type: 'POST', data: {     content_link: content_link.val(),     email: email.val(), viewportsize: viewport_size, browser: user_browser, os: user_os, current_page: current_page   }, success: function () { $('.submit-modal .screen-1').delay(1000).fadeOut(300, function () { $('.submit-modal .screen-1').fadeOut(500, function () { $('span.loading2').detach(); $('.submit-modal .screen-2').fadeIn(500, function () { $('.submit-modal .screen-2').append(''); }); $('.submit-modal .screen-2').css('display','block').delay(4200).fadeOut(500, function () { $('.carlton').hide(); $('.submit-modal .screen-1').fadeIn(500); content_link.val(''); email.val(''); content_link.focus(); email.removeClass('form-validation-error'); $('.submit-modal-button').removeAttr('disabled'); }); }); }); } }); return false; } }); } EXAMPLE.processSubmitModal();
show the html code of the form

以上就是Prevent AJAX form from submitting twice?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏