【问题标题】:Internet Explorer 9 and angular-file-upload not working properlyInternet Explorer 9 和 angular-file-upload 无法正常工作
【发布时间】:2015-09-04 12:32:13
【问题描述】:

我正在尝试使用 Angular 上传文件,除了在 IE9 上,它运行良好。

我尝试了https://github.com/danialfarid/ng-file-upload,但在使用非 HTML5 浏览器时需要 Flash,所以它不适合我。

之后我尝试了https://github.com/nervgh/angular-file-upload 并且工作正常!除了上传文件后我做了一些处理,可能会通过错误请求返回错误。这在 IE9 中不起作用。如果上传成功,我的代码不会看到错误请求。

好吧,我真的不认为问题出在我的代码上,所以我不会在这里发布任何内容。 我想要的是有同样问题的人来告诉我该怎么做。

编辑:换句话说。在 Chrome 中,状态为 400,在 IE9 中为 200。

uploader.onCompleteItem = function (fileItem, response, status, headers)

EDIT2:我想我找到了错误的根源。这是一个角度文件上传功能

iframe.bind('load', function() {
   try {
   // Fix for legacy IE browsers that loads internal error page
   // when failed WS response received. In consequence iframe
   // content access denied error is thrown becouse trying to
   // access cross domain page. When such thing occurs notifying
   // with empty response object. See more info at:
   // http://stackoverflow.com/questions/151362/access-is-denied-error-on-accessing-iframe-document-object
   // Note that if non standard 4xx or 5xx error code returned
   // from WS then response content can be accessed without error
   // but 'XHR' status becomes 200. In order to avoid confusion
   // returning response via same 'success' event handler.

   // fixed angular.contents() for iframes
        var html = iframe[0].contentDocument.body.innerHTML;
     } catch (e) {}

         var xhr = {response: html, status: 200, dummy: true};
         var headers = {};
         var response = that._transformResponse(xhr.response, headers);

         that._onSuccessItem(item, response, xhr.status, headers);
         that._onCompleteItem(item, response, xhr.status, headers);

但我的反应总是不确定的

【问题讨论】:

  • 错误请求不起作用?你应该发布你的代码..
  • 观察网络我可以看到错误的请求响应。但是,在 IE9 中,上传者没有捕捉到错误。在调试中,我可以看到属性 isError 设置为 false。代码在这里真的不重要。
  • 您设置了哪些标头以使其成为错误请求? 400?
  • 我想出了一个解决办法。在我的项目中,如果服务器返回错误,它只会输入 catch 语句。所以我在那里触发了 onError 事件。感谢您的宝贵时间。

标签: angularjs internet-explorer-9 angular-file-upload


【解决方案1】:

我想出了一个解决办法。在我的项目中,如果服务器返回错误,它只会输入 catch 语句。所以我触发了 onError 事件。

【讨论】:

  • 你好 Rafael,你愿意详细说明一下吗?
  • 我在这里遇到了同样的问题。我的代码在 Firefox 上运行良好,但在 IE9 下,我的服务器生成的 400 Bad Request 响应(带有 JSON 正文)永远不会到达 onErrorItem 回调(我看到的是未定义)。
  • 你好 seuvitor,我真的不知道为什么,但是插件不能在 IE9 中得到这个错误。它只能知道请求不起作用(catch 语句)。问题是,有一种情况,即使是 OK 响应也会进入 catch(关于 cors 的东西)。因此,即使服务器返回错误,插件也会发送 200 OK。我在我的项目中更改了这一行,所以我可以看到错误。
猜你喜欢
  • 1970-01-01
  • 2017-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-27
  • 2011-07-11
  • 1970-01-01
  • 2020-11-04
相关资源
最近更新 更多