而使用JQuery用户界面对话框提交行动击中两次 [英] Submit action getting hit twice while using JQuery UI Dialog

查看:134
本文介绍了而使用JQuery用户界面对话框提交行动击中两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写使用jQuery和引导一个ASP.NET MVC应用程序4

I am writing an ASP.NET MVC 4 application using JQuery and bootstrap.

有在我的网站模式对话框功能,这用来工作的顺利开展,直到最近,当彼此开发商的确在一些网站相关的造型变化。

There is a modal dialog functionality in my site which used to work smoothly until recently when one another developer did some styling related changes in the website.

以下是code我已经写在我的部分观点之一,我在一个jQuery对话框打开此:

Following is the code I have written in one of my partial view, I am opening this in a JQuery dialog:

@using (Ajax.BeginForm("ChangeStatus",
    new AjaxOptions { UpdateTargetId = "AboutOrderContainer", HttpMethod = "POST" }))
{
    @Html.HiddenFor(m => m.OrderId)
    <table class="row-fluid">
        <tr>
            <td></td>
        </tr>
        <tr>
            <td>
                Comments&nbsp;(Optional):
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td>
                @Html.TextAreaFor(m => m.Comments, new { @maxlength = 255, @rows=5 })
            </td>
        </tr>        
        <tr>
            <td>                
                <center>
                <input type="submit" title="OK" value="OK" class="btn" />
                    </center>
            </td>
        </tr>
    </table>        
}

这是较早的做工精细,无论作为一个用户点击OK按钮,在ChangeStatus行动得到调用,一种观点得到刷新。

This was earlier working fine, as whenever a user hits "OK" button the "ChangeStatus" action was getting called, and a view was getting refreshed.

但现在,在这之后开发商已经做了一些变化,ChangeStatus击中两次异步导致运行时错误。我不知道是什么原因造成的问题。

But now, after that developer has done some changes, the "ChangeStatus" getting hit twice asynchronously which results in run-time errors. I am not sure what is causing the issue.

以下是同时加载这个对话框被加载脚本文件:

Following are the script files that gets loaded while this dialog is loaded:


  1. ajax.dialog.custom.js

  2. bootstrap.js

  3. jQuery的-1.9.1.js

  4. jQuery的-迁移-1.1.1.js

  5. 的jQuery-UI-1.10.2.js

  6. jQuery的-不显眼-ajax.js

  7. jquery.validate.js

  8. jquery.validate.unobtrusive.js

  9. Modernizr的-2.5.3.js

  10. onmediajquery.js

  11. ecommercesite-custom.js

所有脚本文件(除了ecommercesite-custom.js)从JQuery的库和引导网站。
以下是ecommercesite-custom.js文件code:

All script files (except, ecommercesite-custom.js) are libraries from JQuery, and bootstrap sites. Following is the code of ecommercesite-custom.js file:

$(document).ready(function () {

    $('input[class*=btn-submit]').click(function (event) {
        if (($(this).closest('form').valid())) {
            $(this).attr("disabled", true);
            $(this).closest('form').submit();
        }
        else {
            $(this).attr("disabled", false);
        }
    });

});

我不知道什么是错在这里。我曾尝试删除上述的js文件(即第11号),但它是没有帮助。所以,你可以忽略上述文件的任何影响,同时考虑解决方案。

I am not sure what is wrong here. I have tried removing the above js file (i.e. no. 11), but it was of no help. So you can ignore any implications of the above file while thinking about the solution.

任何人有什么想法?
重申一个事实,即在同一code的工作得很好,直到其他开发商改变了一些造型功能。

Anyone has any idea? Reiterating the fact that the same code was working very well until the other developer changed some styling functionality.

推荐答案

我改变jquery.unobtrusive-ajax.js文件跳过异步调用,如果提交按钮具有特定的自定义属性修正了这个问题。

I fixed this issue by changing jquery.unobtrusive-ajax.js file to skip async call if the submit button is having a particular custom attribute.

这篇关于而使用JQuery用户界面对话框提交行动击中两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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