jQuery ajax表单仍然提交两次

时间:2016-02-22 16:13:07

标签: jquery ajax submit

我已经尝试了this问题答案中报告的所有选项。 我有这个:

$('form').submit(function (e) {
        e.preventDefault();
        e.stopImmediatePropagation();
        if ($(this).valid()) { 
            var postingWindow = $("#postingDialogWindow").data("kendoWindow");
            postingWindow.title("Posting Client Request...");
            postingWindow.open();

            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize()
            })
            .success(function (result) {
                if (result.success) {
                    window.alerts.info(result.message, true);
                    window.location.replace(result.redirecturl);
                }
                else {
                    window.alerts.error(result.error);
                }
            })
            .fail(function (result) {
                //window.alerts.error(result);
                var result = $.parseJSON(result.responseText);
                window.alerts.error(result.errorMessage);
            })
            .always(function (data) {
                postingWindow.close();
            });
        }
        return false;
    });

但我仍然有两次提交的ajax表格。请帮忙。我的斗智尽头。

编辑:添加了表单的html:

@using (Html.BeginForm("Create", "ClientWarehouseRequest", FormMethod.Post, new { @class = "form-horizontal" }))
    {
    <!--...whole lotta input fields here...-->

 <div class="buttons-wrap">
            <input type="hidden" name="SubmitButtonValue" id="SubmitButtonValue" />
            <input class="k-button" type="submit" value="Post" name="SubmitButton" />
            @Html.ActionLink("Cancel", "Index", controllerName: null, routeValues: null, htmlAttributes: new { @class = "k-button", style = "vertical-align: bottom;" })
            <input class="k-button" type="submit" value="Save" name="SubmitButton" />
        </div>

    }

编辑2: 我已尝试按this新问题中的解释重新处理该方法,但后来我遇到的问题是表单是由浏览器提交的,而不是ajax。

请帮忙。我不再是一个软件工匠了!

0 个答案:

没有答案
相关问题