简体   繁体   English

jQuery.form提交与IE有关的问题(7-9,可能是10)

[英]jQuery.form submitting issues with IE (7-9, possibly 10)

I'm trying to get a form submission work in IE. 我正在尝试在IE中进行表单提交工作。 What I have works in Chrome, FF, Opera and Safari. 我在Chrome,FF,Opera和Safari中都能使用。 I believe it works in IE10 as well, but I don't have the equipment here to test that out again (I've tested this before in IE10, it worked fine. I've made some changes to the page, but I'm pretty sure the changes didn't impact this form). 我相信它也可以在IE10中使用,但我没有这里的设备可以再次进行测试(我之前在IE10中已经对此进行了测试,效果很好。我对页面进行了一些更改,但我非常确定更改不会影响此表单)。

Basically, I have form that submits a record but is submitted with the jquery.form control: 基本上,我有一个提交记录的表单,但使用jquery.form控件提交:

<form action="@Url.Content("/ActivitySubmission/SubmitWork")" class="activityForm" id="formId-@(item)" method="post">

and the jQuery code to handle the submit: 和jQuery代码来处理提交:

$(".activityForm").submit(function (e) {
        e.preventDefault();

        var parts = $(this).prop("id").split("-");
        var activityTemplateId = parts[3];
        var resultsDivId = "#activityResults" + activityTemplateId;
        var msg = '<div style="height:40px; margin-right:20px; float:left;"><img src="/Content/Images/loadingSpinner.gif" /></div>' +
            'Saving your work...<div style="clear:both;"></div>';
        $(resultsDivId).html(msg).slideDown();

        var action = $(this).prop("action");

        $(this).ajaxSubmit({
            url: "/ActivitySubmission/SubmitWork",
            data: {activityTemplateId: activityTemplateId},
            iframe: true,
            target: resultsDivId,
            dataType: 'json',
            success: function (data, textStatus, jqXHR) {
                var parts = data.split("|");
                var status = parts[0];
                var message = parts[1];
                $(resultsDivId).html('<div class="activitySuccess">' + message.replace("\"", "") + '</div>');

                $("#reloadReminder").fadeIn("1200");

                return false;
            },
            error: function(jqXHR, textStatus, errorThrown){
                $(resultsDivId).html('<div class="activityError">Sorry, unable to act on your save or submit command.  Please let the monitor know.</div>');
                alert(errorThrown);
                return false;
            }
        });

        return false;
    });

In IE, the form will post, and run the code in the controller (/ActivitySubmission/SubmitWork) BUT when it comes back to the page, it doesn't run the "success" method of the .ajaxSubmit({...}); 在IE中,该表单将返回并返回到页面,并在控制器(/ ActivitySubmission / SubmitWork)BUT中运行该代码,但它不会运行.ajaxSubmit({...}); it just gives me a "save/open/run" dialog: 它只是给我一个“保存/打开/运行”对话框:

保存对话框

Any thoughts as to why this is happening in IE and how I can change this? 关于为什么在IE中发生这种情况以及如何更改这种情况有任何想法吗?

If you're getting the "save/open/run" dialog unexpectedly on an ajax call, it means that the server is not providing the correct mime-type information in the HTTP headers, so the browser is mis-identifying the response as a file that needs to be downloaded. 如果您在ajax调用中意外获取“保存/打开/运行”对话框,则意味着服务器未在HTTP标头中提供正确的mime类型信息,因此浏览器将响应错误地标识为需要下载的文件。

You need to add a HTTP header that specifies the kind of data being sent. 您需要添加一个HTTP标头,该标头指定要发送的数据类型。 For example, in this case it looks like you're sending an HTML snippet, so send a header that specifies text/html . 例如,在这种情况下,您似乎正在发送HTML代码段,因此发送一个指定text/html的标头。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM