且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过更改事件防止两次提交表单

更新时间:2023-02-05 19:39:28

最后,我提出了解决方案!事实是……正如Mike C.所说,额外的代码可以帮助解决问题.问题是我要提交的表单是MVC的Ajax.BeginForm,所以..主要问题是该表单的ajax提交,这是第二个提交!

Finally i came out with a solution! The thing was that.. as Mike C. says, the extra code could help to solve the problem. The problem was that the form that i'm trying to submit it's an Ajax.BeginForm of MVC so.. the main problem is the ajax submit of that form, that was the second submit!

我无法更改该行为..仅更改带有Html.Beginform ..的Ajax.Beginform ..我不想做的事情.所以..我想到了这个生锈"的解决方案:

I couldn't change that behavior.. only changing the Ajax.Beginform with a Html.Beginform.. thing that i don't want to do. So.. i came out with this "rusty" solution:

$("input.price").live('keypress', function (e) {
     if (e.keyCode == 13) {
        $(this).attr('data-submitting', true);
     }
});

$("input.price").live('change', function (e) {
     if (!$(this).attr('data-submitting')) {
         $(this).closest('form').submit();
     }
});