表格提交两次

时间:2018-06-22 12:18:15

标签: javascript asp.net-mvc

我有一个asp.net MVC应用程序。

以下javascript代码自10天前开始生产。这个想法是拦截提交事件并调用ajax事件以检查附件大小,然后再允许提交表单。

问题:我们报告了2位用户两次提交了表单。我不知道这怎么可能。也许使用较旧的IE版本?

$(function () {

   $("input[type=submit]").bind("click", function (e) {

      e.preventDefault();
      e.returnValue = false;

      var $form = $(this);

      $.ajax({
        type: 'post',
        url: pMailPreview.checkAttachmentsSizeExceedUrl,
        cache: false,
        context: $form,
        success: function (result, textStatus, XMLHttpRequest) {
            if (result.sizeExceed) {
                alert('Size exceed !!');
            } else {
                // make sure that you are no longer handling the submit event; clear handler
                this.off('submit');
                // actually submit the form
                this.submit();
            }
        },
        error: function (jqXhr, textStatus, errorThrown) {
            alert("Error '" + jqXhr.status + "' (textStatus: '" + textStatus + "', errorThrown: '" + errorThrown + "')");
        },
      });

      return false;

  });

});

1 个答案:

答案 0 :(得分:-1)

如果用户在按钮上单击两次,则该表单有效,它将发送两次。

您可以禁用提交按钮。

相关问题