javascript - jQuery $(form).submit() 仅针对 IE(MVC3 应用程序)不触发

标签 javascript asp.net-mvc-3 forms internet-explorer submit

我一直在搜索互联网(包括 SO),但我找不到任何可以帮助我解决我的情况的东西,所以希望我能从你们那里得到一些帮助。

基本上,如标题所说,.submit() 不会在 IE 中触发。所有其他浏览器都可以正常工作,但在 IE(目前为 8、9、10)中,它只是不会触发提交。

查看代码如下:

        <form id="@formId" method="post" enctype="multipart/form-data" action="@Url.Content("/ActivityEvent/SubmitCheckpointApproval")">
            <table id="checkpoint-approval" style="width:100%" align="center" class="noBorders">
                <tr>
                    <td style="width: 520px;">
                        <div>
                            Please enter any relevant comments:
                        </div>
                        <div style="margin: 10px 0;">
                            <textarea class="wysiwygSimple" rows="4" cols="60" name="comment" id="checkpoint-comment-@(actTplId)"></textarea>
                        </div>
                    </td>
                    <td style="border: 0; padding-top: 30px; text-align: center; width:70px;">
                        <img alt="key" src="/Content/Images/checkmarkInCircle.png" align="middle" style="width: 100px;
                            height: 100px;" /><br />
                        <p style="text-align: left; margin-top: 10px;">
                            The notes and resources entered here are shared with the student.</p>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" class="ResourcesUploadList">
                        Suggest some resources:<br />
                        <div style="float: left;">
                            <input class="Multi" type="file" name="resourceFiles[]" /></div>
                        <div style="float: left; margin-left: 10px; font-style: italic;">
                            (click browse for each file you want to upload)</div>
                        <div style="clear: both;">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="border: 0; text-align: center; width:600px;" colspan="2">
                        @if (hasAdminRights)
                        {
                            <input type="button" @Html.Raw(btnStyle) class="activityApprove" name="actionApprove" id="actionApprove" value="Tutor Completion Approval" title = "Approves all activities preceding this checkpoint as complete." onclick="Activity.submitCheckpointApproval('@(formId)', '@(ActivityEvent.EVENT_TYPE_APPROVED)',@(actTplId));" />
                            <input type="button" @Html.Raw(btnStyle) class="activityAttention" name="actionAttention" id="actionAttention" value="Needs Attention" title = "Notifies the student that this project needs additional work prior to completion." onclick="Activity.submitCheckpointApproval('@(formId)', '@(ActivityEvent.EVENT_TYPE_NEEDS_ATTENTION)',@(actTplId));" /> 
                        }
                        <input type="button" @Html.Raw(btnStyle) value="Cancel" title = "Close this." onclick="javascript:$('#checkpoint-approval@(actTplId)').toggle();" />
                    </td>
                 </tr>
            </table>
        </form>

点击按钮时:

Activity = {

submitCheckpointApproval: function (formId, activityEventStatusId, activityTemplateId) {
    var resultsDivId = $("#checkpointResults" + activityTemplateId);
    Activity.showCheckpointLoading(resultsDivId); //Just shows a spinner for loading
    $("#checkpoint-activityEventStatusId-" + activityTemplateId).val(activityEventStatusId);
    $("#" + formId).submit(); //PROBLEM IS HERE??
},
...
};

最后, Controller :

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult SubmitCheckpointApproval()
         //Save everything in here
    }

在 IE 中调试时,我到达 js 中的 .submit() 行,并从那里运行它。之前的一切都很好,但随后 .submit() 出现并且它停止做任何事情。没有 javascript 错误,控制台中没有任何内容,根本没有任何问题的迹象。 在所有其他浏览器中,.submit() 会正常触发,并且 Controller 会中断被调用的方法。

关于为什么在 IE 中会发生这种情况有什么想法吗?我敢肯定有人以前遇到过这个!!请帮忙,我整个下午都在用脑袋敲 table !

谢谢大家!

最佳答案

我有一个类似的错误。我的解决方案是:

将 JS 表单附加到 DOM 中的一个 div,这样 IE 就知道它在那里并可以提交它。

希望对你有帮助

关于javascript - jQuery $(form).submit() 仅针对 IE(MVC3 应用程序)不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16201278/

相关文章:

javascript - list 中是否有可能有两个单独的 css 文件,影响两个单独的域?

javascript - 如何访问 JSON 同级 "keys"?

asp.net - Windows Azure : How to 301 non-www url to www for a domain

javascript - 在表单标签中插入 <noscript> 或类似内容(HTML、JavaScript)

php - 表单中的多个提交按钮

PHP:这对恶意输入安全吗?

javascript - 在播放 youtube iframe 嵌入时触发事件

javascript - 在 View 之间移动而不刷新/重新加载

C# ASP .NET MVC 3单例构造函数调用两次

c# - razor 文件中的 @functions 代码块有什么作用,我应该何时(如果有的话)使用它?