0

I've tried all the options reported in the answers to this question. I have 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;
    });

But I STILL have the ajax form submitting twice. Please help. I'm at my wits end with this.

EDIT: Added the html for the form:

@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>

    }

EDIT 2: I've tried reworking the approach as explained in this new question, but then I have the problem that the form is submitted by the browser and not ajax.

Please help. I'm not feeling like a much of a software craftsman anymore!

Community
  • 1
  • 1
Shawn de Wet
  • 5,642
  • 6
  • 57
  • 88

0 Answers0