Javascript jquery避免表单提交两次

Javascript jquery避免表单提交两次,javascript,jquery,ajax,forms,Javascript,Jquery,Ajax,Forms,我在ASP.NET MVC应用程序中有此表单: @using (Ajax.BeginForm("SaveTransaction", "Addons", new AjaxOptions() { HttpMethod = "POST" }, new { id = "TransForm", enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() ... } 我使用这个jQuery代码提交表单,但它提交表单两次 (f

我在ASP.NET MVC应用程序中有此表单:

@using (Ajax.BeginForm("SaveTransaction", "Addons", new AjaxOptions() { HttpMethod = "POST" }, new { id = "TransForm", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    ...
}
我使用这个jQuery代码提交表单,但它提交表单两次

(function () {
    var bar = $('.progress-bar');
    var percent = $('.progress-bar');
    $('#TransForm').ajaxForm({
        beforeSend: function () {
            var percentVal = '0%';
            bar.width(percentVal)
            percent.html(percentVal);
            percent.fadeIn();
        },
        uploadProgress: function (event, position, total, percentComplete) {
            var percentVal = percentComplete + '%';
            bar.width(percentVal)
            percent.html(percentVal);
        },
        success: function (data) {
            var percentVal = '100%';
            bar.width(percentVal)
            percent.html(percentVal);
            percent.fadeOut();

            // Get addonID
            var ID = $('#BatchID').val();

            //Resets form
            ClearSelection();

            //update the partial views
            UpdateEvents(ID);

        },
        error: function (data) {
            ReturnStatus("alert-danger", 'data.responseText');
        },
        complete: function (data) {
            ReturnStatus("alert-success", message);
        }
    });

})();
只要提交、保存和返回正确的数据两次,这段代码就可以正常工作


我试图在发送前包含
:函数(e)…
,然后是
e.preventDefault(),但它没有改变任何东西。如何将其更改为包含
e.preventDefault()
这样表单就不会发送两次了?

ajaxForm
不是一个jQuery函数,而且可能有不同的插件用于jQuery添加一个
ajaxForm
函数,所以你应该知道你使用的是哪个插件。试着利用文档中的这一部分:如果“beforeSubmit”回调返回false,那么表单将不会被提交。或者,您可以尝试使用jQuery的
.one()
method.t.niese,我正在使用插件jQuery.form.min.js