我只在IE <10中得到了这样的问题:

$("input:file#upload-photo").fileupload({
    enctype: "multipart/form-data",
    url: $("input:file#upload-photo").attr("url"),
    autoUpload: true,
    send: function() {
        spinner.spin(target);
    },
    done: function (e, data) {
        spinner.spin(false);

        var errors = data.result.Errors;
        if (errors != null && errors.length > 0) {
            for (var i = 0; i < errors.length; i++) {
                var ul = $("<ul>").html("<li>" + errors[i] + "</li>");
                $('#upload_photo_errors').html(ul);
            }
        } else {
            $(".profile-photo").attr("src", data.result.Data.AvatarUrl);
        }
    },
    error: function() {
        spinner.spin(false);
    }
});
.

'发送'处理程序被调用,“错误”处理程序也是如此。

我抓住了我的小提琴手的请求。它没有内容类型和任何数据:

POST http://172.20.40.45/site/api/Users/Avatar HTTP/1.1
X-Requested-With: XMLHttpRequest
Accept: */*
Referer: http://172.20.40.45/site/Profile/Edit
Accept-Language: ru
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
Host: 172.20.40.45
Content-Length: 0
DNT: 1
Connection: Keep-Alive
Pragma: no-cache
Cookie: ...
.

我试图在 http://blueimp.github.io/jquery-file-上上载上载proccess上传/ 。它在IE9中工作正常。为什么在我的情况下不起作用?

有帮助吗?

解决方案

我已经解决了这个问题。 起初我解决了多部分/形式数据有效载荷的问题。IE9不支持XHR文件上传。因此,我添加了下一个脚本:

<script src="~/Scripts/jquery.iframe-transport.js"></script>
.

我还在专门为IE9中添加另一个脚本:

<!--[if lt IE 10]>
<script src="~/Scripts/jquery.xdr-transport.js"></script>
<![endif]-->
.

现在浏览器上传文件。但我面临着另一个问题。这次我有这样的问题。我使用Web API,我找到了这个解决方案它帮助了我。

但现在调用'错误'处理程序而不是'完成'。要解决此问题,我们必须将数据类型设置为“JSON”。最终版本如下所示:

$("input:file#upload-photo").fileupload({
    dataType: "json",
    url: $("input:file#upload-photo").attr("url"),
    autoUpload: true,
    send: function() {
        spinner.spin(target);
    },
    done: function (e, data) {
        var errors = data.result.Errors;
        if (errors && errors.length) {
            var items = $.map(errors, function (i, error) {
                return $("<li>").text(error);
            });
            $("<ul>").append(items).appendTo('#upload_photo_errors');
        } else {
            $(".profile-photo").attr("src", data.result.Data.AvatarUrl);
        }
    },
    always: function() {
        spinner.spin(false);
    }
});
.

其他提示

The problem for me was that IE9 does not send the file if you trigger the file input through JS, the user actually needs to click the browse button for it work.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top