【发布时间】: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