jQuery文件上傳不會在IE9中發送文件

[英]jQuery File Upload doesn't send a file in IE9


I have got such problem only in IE < 10. My sources:

我只在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);
    }
});

The 'send' handler is invoked and the 'error' handler is too.

調用'send'處理程序並且'error'處理程序也是如此。

I caught my request in Fiddler. It has no Content-Type and any data:

我在Fiddler抓住了我的要求。它沒有Content-Type和任何數據:

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: ...

I have tried to check the uploading proccess on the http://blueimp.github.io/jQuery-File-Upload/. It works fine in IE9. Why does it not work in my case?

我試圖在http://blueimp.github.io/jQuery-File-Upload/上檢查上傳過程。它在IE9中運行良好。為什么它在我的情況下不起作用?

2 个解决方案

#1


20  

I have solved this issue. At first I solved the problem with multipart/form-data payload. IE9 doesn't support XHR file upload. Therefore I added next script:

我已經解決了這個問題。起初我用multipart / form-data有效載荷解決了這個問題。 IE9不支持XHR文件上傳。因此我添加了下一個腳本:

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

Also I added another script specially for IE9:

另外我還為IE9添加了另一個腳本:

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

Now the browser uploads the file. But I faced another problem. This time I had such problem. I use Web API and I found this solution which helped me.

現在瀏覽器上傳文件。但我遇到了另一個問題。這次我遇到了這樣的問題。我使用Web API,我找到了這個幫助我的解決方案。

But now the 'error' handler is invoked instead of 'done'. For solving this issue we must set dataType to 'json'. The final version looks so:

但現在調用'錯誤'處理程序而不是'完成'。為了解決這個問題,我們必須將dataType設置為'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);
    }
});

#2


4  

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.

對我來說問題是如果你通過JS觸發文件輸入,IE9不會發送文件,用戶實際上需要單擊瀏覽按鈕才能正常工作。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/06/04/72f15a0eca7237db654172e460c64caa.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com