【问题标题】:IE tries to download json response when using ajaxForm jQuery pluginIE 在使用 ajaxForm jQuery 插件时尝试下载 json 响应
【发布时间】:2015-03-29 20:07:34
【问题描述】:

我已经尝试了所有方法,但不知道问题出在哪里。

问题:IE在提交前下载json响应+不触发。

我使用的是 IE 11。

我正在使用 jQuery - ajaxForm 插件。 用它实现文件上传。 在 chrome 上一切都完美而在 IE 上一切都没有。

IE 尝试下载 json 响应并且在功能之前不做插件。

JS代码:

var options = {
    beforeSend: beforeSubmit,
    uploadProgress: progressSubmit,
    success: uploadSuccess,
    complete: completeSubmmit
};

form.ajaxForm(options);

手动点击执行的实际请求。

('#submitBtn').click();

我正在使用 MVC-3 控制器,HttpPost 操作接收 HttpPostedFile。 响应是一个包含多个字符串的简单 ViewModel。

我已经尝试了以下所有方法,没有任何效果。

尝试:

Response.Headers.Remove("Content-Type");
Response.Headers.Add("content-type", "application/json");

return Json(vm, "text/html");
return Content(JsonSerializerHelper.Serialize(vm), "text/html");
return Json(vm);

提琴手:

Chrome 请求:

Content-Length: 606
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
Content-Type: multipart/form-data; boundary=----    WebKitFormBoundary4ABojutLkBGFbphB
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.8,he;q=0.6,pt;q=0.4,ru;q=0.
Content-Disposition: form-data; name="file"; filename="customersBulk.csv"
Content-Type: application/vnd.ms-excel

Chrome 响应:

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
Date: Thu, 29 Jan 2015 18:19:47 GMT
Content-Length: 469

-- and the actual Json object. --

IE 请求:

Accept: text/html, application/xhtml+xml, */*
Accept-Language: he-IL
Content-Type: multipart/form-data; boundary=---------------------------7df28b2e1c126c
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Content-Length: 691
DNT: 1
Host: localhost
Pragma: no-cache
Content-Disposition: form-data; name="file";     filename="MY_PATH\..\customersBulk.csv"
Content-Type: application/vnd.ms-excel
-----------------------------7df28b2e1c126c--

IE 响应:

HTTP/1.1 200 OK
Cache-Control: private, s-maxage=0
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-Frame-Options: SAMEORIGIN
Date: Thu, 29 Jan 2015 18:15:50 GMT
Content-Length: 558

-- and the Json as well. --

版本: jQuery 表单插件

版本:3.50.0-2014.02.05
需要 jQuery v1.5 或更高版本

有什么想法吗?

【问题讨论】:

    标签: jquery asp.net-mvc-3 internet-explorer ajaxform


    【解决方案1】:

    你能不能试试下面的东西:

    $('#YourFormId').bind('submit', function() { return false; });
    

    这将阻止原始表单提交过程。

    【讨论】:

      猜你喜欢
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 2019-09-10
      • 2012-01-25
      • 1970-01-01
      相关资源
      最近更新 更多