Javascript blueimp jquery 文件上传 - “完成”、“完成”回调不适用于 IE 9

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10122165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 23:57:07  来源:igfitidea点击:

blueimp jquery file upload - "done", "complete" callbacks not working for IE 9

javascriptjqueryfile-uploadasyncfileuploadblueimp

提问by tanushree

I am using Blueimp Jquery File Uploadplugin to upload files asynchronously. It works well in most other browsers (with a few minor issues) - on IE, I see this issue that the "done", "stop", "always", "complete" and some other event callbacks are not getting invoked.

我正在使用Blueimp Jquery 文件上传插件异步上传文件。它在大多数其他浏览器中运行良好(有一些小问题)——在 IE 上,我看到这个问题是“完成”、“停止”、“总是”、“完成”和其他一些事件回调没有被调用。

While debugging, I added console.logs in the "done", "fail", "always", and added a "complete" method to the ajax request in the _onSend function (in jquery.fileupload.js) - but none of them seem to get invoked in IE.

在调试时,我在“完成”、“失败”、“总是”中添加了 console.logs,并在 _onSend 函数(在 jquery.fileupload.js 中)的 ajax 请求中添加了一个“完整”方法 - 但没有一个似乎在 IE 中被调用。

_onSend: function (e, data) {
        var that = this,
            jqXHR,
            slot,
            pipe,
            options = that._getAJAXSettings(data),
            send = function (resolve, args) {
                that._sending += 1;
                jqXHR = jqXHR || (
                    (resolve !== false &&
                    that._trigger('send', e, options) !== false &&
                    (that._chunkedUpload(options) || $.ajax(options))) ||
                    that._getXHRPromise(false, options.context, args)
                ).complete(function (result, textStatus, jqXHR) {
                    console.log("complete"); 
                }).done(function (result, textStatus, jqXHR) {
                    console.log("done", result); 
                }).fail(function (jqXHR, textStatus, errorThrown) {
                    console.log("fail", result); 
                }).always(function (a1, a2, a3) {
                    console.log("done", result); 

                   }
                });
                return jqXHR;
            };

[plugin code trimmed for readability]

[修剪插件代码以提高可读性]

I understand that in IE 9, jquery.iframe-transport.js used for the file upload (as XHR file uploads are not supported in IE).

我知道在 IE 9 中,jquery.iframe-transport.js 用于文件上传(因为 IE 不支持 XHR 文件上传)。

I'm not sure how I should go about fixing/ debugging this issue.

我不确定我应该如何修复/调试这个问题。

Thanks!

谢谢!

回答by tanushree

The done event gets fired if the content-type of the response is set to "text/html" or "text/plain" (instead of application/json) when json is being returned from the server. This applies only for browsers that do not support XHR file upload (such as IE9) and where the blueimp plugin is using IFrame transport instead.

当服务器返回 json 时,如果响应的内容类型设置为“text/html”或“text/plain”(而不是 application/json),则触发 done 事件。这仅适用于不支持 XHR 文件上传(例如 IE9)以及 blueimp 插件使用 IFrame 传输的浏览器。

Related info under "Content Negotiation" in the plugin documentation: https://github.com/blueimp/jQuery-File-Upload/wiki/Setup

插件文档中“内容协商”下的相关信息:https: //github.com/blueimp/jQuery-File-Upload/wiki/Setup

回答by Calvin Correli

For the record, I ran into this problem when uploading direct to S3, now that their CORS feature allows for that.

作为记录,我在直接上传到 S3 时遇到了这个问题,因为他们的 CORS 功能允许这样做。

The solution was to set success_action_status to '200', and then the Done event was triggered correctly.

解决方法是将success_action_status设置为'200',然后Done事件就被正确触发了。

回答by hraynaud

In case anyone is still having this issue with direct upload to S3 the solution is to add a success_action_statusfield with the value of "201". Make sure that that you include it as part of the policy data as well since they have to match.

如果有人在直接上传到 S3 时仍然遇到此问题,解决方案是添加值为“201”的success_action_status字段。确保您也将其作为策略数据的一部分包含在内,因为它们必须匹配。

Apparently when receiving the upload from IE9 S3 will return an empty string. To get it to return XML, which the file uploader needs, you have to tell it return a status of 201.

显然,当从 IE9 S3 接收上传时将返回一个空字符串。为了让它返回文件上传器需要的 XML,你必须告诉它返回 201 的状态。