IE在AngularJS中使用$ http服务上传文件时生成额外请求。 [英] IE generating extra request when using $http service in AngularJS to upload a file.

查看:63
本文介绍了IE在AngularJS中使用$ http服务上传文件时生成额外请求。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,需要根据公司政策在IE中完全可用。

我创建了一个上传文件的功能。我在服务器端使用AngularJS 1.5.8版和Web API 2。这是发出上传请求的代码:

Hi, I'm developing an app, that need to be fully available in IE as per company policies.
I created a feature to upload files. I'm using AngularJS version 1.5.8 with Web API 2 in the server side. This is the code that makes the request for the upload:

               dataService.uploadCsvFile = function (uploadUrl, file) {
                   return $http({
                       method: 'POST',
                       url: uploadUrl,
                       headers: { 'Content-Type': undefined },
                       transformRequest: function () {
                           var formData = new FormData();
                           formData.append("file", file);
                           return formData;
                       },
                       data: { file: file }
                   })
               };

此功能在chrome中运行良好,我得到了预期的结果。如果我转到Chrome中的开发者工具中的网络部分,我看到只有一个请求,响应为200,这意味着没有错误。

This feature works well in chrome and I get the expected results. If I go to the Network section in the Developer Tool in Chrome I see only one request have been made and the response is 200 which means no error.

当我使用IE时出现问题,我在IE中得到的完全相同的请求的开发人员工具是两个请求,其中一个响应是500(内部错误),第二个响应是200(确定)。 

The issue appears when I use IE, what I get in IE the developer tool for the exact same request is two requests have been made, one of them response is 500 (Internal Error), and the second one response is 200 (Ok). 

API方法中的代码没有问题,它在chrome中长时间运行良好。

The code in API method have no issue, it have worked well for long time in chrome.

这种行为有什么解释吗?我应该怎么做以防止在我的应用程序中发生这种情况,所以我没有收到任何错误?

Is there any explanation for this behavior? What Should I do to prevent this from happening in my app, so I don't get any error?

推荐答案

内容类型未定义。您必须指定MSIE浏览器的类型,否则请求被设置两次....

content type is undefined. You MUST specify the type for MSIE browsers, otherwise the request is set twice....

同样适用于嵌入元素...例如。

same applies for embed elements... eg.

< object data =" csvfile.csv">< / object>因为第一个请求中没有内容类型,所以会发送两个请求。

<object data="csvfile.csv"></object> will sent two requests since there is no content type in the first request..

< object data =" csvfile.csv"类型= QUOT;文本/ CSV">< /对象>将包含内容类型标题后发送一个请求。

<object data="csvfile.csv" type="text/csv"></object> will send one request since the content type header is included.

问候。


这篇关于IE在AngularJS中使用$ http服务上传文件时生成额外请求。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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