jQuery:两次提交一个表单 [英] jquery : submitting a form twice

查看:87
本文介绍了jQuery:两次提交一个表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为客户举办的活动为其创建注册表.基本的用户详细信息已提交给第三方系统(即名称,电子邮件等),但是其余字段需要通过电子邮件发送给客户端.

I'm creating a registration form for a client for an event they're hosting. The basic user details are submitted to a third-party system (ie name, email etc.) but the rest of the fields need to be sent via email to the client.

我需要这样的事情发生:

I need something like this to happen :

  1. 列表项
  2. 用户填写表格
  3. jquery bvalidator检查表单中的必填字段
  4. 将表单(通过ajax)提交到单独的页面,然后在该页面中将电子邮件发送给客户
  5. 然后将表单(常规POST方法)提交给第三方系统
  6. 成功用户将被传递回谢谢" URL.

这是我尝试使用的代码,但是它陷入了一个循环,反复将其自身提交到电子邮件"页面,而从未提交给外部URL.

Here is the code I've tried using, but it gets caught in a loop repeatedly submitting itself to the 'email' page, and never submits to the external url.

如果我将$('#form1').submit();替换为警报,它只会向电子邮件页面提交一次,然后正确显示警报.

If I replace the $('#form1').submit(); with an alert it submits only once to the email page and then displays the alert correctly.

var myvalidator = $('#form1').bValidator(optionsGrey);

$('#form1').submit(function() {
  if (myvalidator.isValid()) {

    $.ajax({
      data: $('#form1').serialize(),
      type: "POST",
      url: "email_send.asp",
      success: function() {
        $('#form1').submit();
      }
    });
  }
  return false;
});

关于如何解决此问题的任何建议?

Any suggestions as to how I can fix this?

推荐答案

尝试:


$('#form1').unbind('submit').submit();

这篇关于jQuery:两次提交一个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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