jQuery File Uploader IE9不在Upload上发布任何参数

时间:2012-10-02 22:56:39

标签: javascript jquery file-upload blueimp

我使用jQuery文件上传器插件和rails 3.插件在这里:

https://github.com/blueimp/jQuery-File-Upload

我使用该插件允许用户上传个人资料照片。到目前为止,该解决方案适用于Chrome,Safari和Firefox。但是在IE上失败了。当你在IE中选择一个文件时,插件会发布到服务器但是没有参数,它是一个空帖子。

chrome中的帖子示例:

Started PUT "/api/1/settings/ajax_photo_upload" for 10.0.1.3 at 2012-10-02 15:39:20 -0700
Processing by ApiV1::SettingsController#ajax_photo_upload as JS
  Parameters: {"photo"=>#<ActionDispatch::Http::UploadedFile:0x007f9e4bac2e48 @original_filename="xxxxx.jpeg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"user[photo]\"; filename=\"xxxxx.jpeg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/3x/k1yb0r4s07q1jm82kq93ch180000gn/T/RackMultipart20121002-3633-sxsbtu>>}, "update_type"=>"general"}

但是在IE9中,它不会发送任何内容:

Started PUT "/api/1/settings/ajax_photo_upload" for 10.0.1.10 at 2012-10-02 15:39:31 -0700
Processing by ApiV1::SettingsController#ajax_photo_upload as JS

这是我的实施:

$('input[type="file"]').fileupload({
    url : '/api/1/settings/ajax_photo_upload',
    formData : [{
        name : 'authenticity_token',
        value : $('meta[name="csrf-token"]').attr('content')
    }],
    type : 'PUT',
    dataType: 'json',
    add : function (e, data) {
            data.submit();
    }
});

HTML

<input name="user[photo]" type="file" accept="image/*" >

为什么IE会这样做的任何想法?感谢

3 个答案:

答案 0 :(得分:4)

您使用的是基本插件吗?我当时和我有同样的问题并与它斗争了一天只是为了意识到我没有包含jquery.iframe-transport.js插件:

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

请参阅文档here

哦!并感谢您关于将'authenticity_token'键值对包含为'formData'的片段 - 这有助于我摆脱rails 3警告“警告:无法验证CSRF令牌真实性”

答案 1 :(得分:0)

基本上是关于html 5数据标签的支持。 IE9存在严重问题。例如,当您上传图像时,在Chrome中它会搜索数据:blob并在实际上传图像之前为您提供预览。在IE中,你不能。在IE9中查看Gmail的邮件附件屏幕,您将看到不同之处。如果是大型项目,我建议您使用flash作为图像上传器。

答案 2 :(得分:0)

    $("#txt1").fileupload({
        replaceFileInput: false,
        dataType: "json",        
        datatype:"json",
        url: "<%=Page.ResolveUrl("~/WebService/AddAttachment.ashx")%>",
        done: function (e, data) {
            $.each(data.result, function (index, value) {
         //You get the response data in here from your web service
            })
            $("#txt1").val("");
        }`enter code here`
    });

这在IE8和IE9 +上面都经过测试并正常工作。请确保使用正确的dataType:“json”(或数据类型:“json”),并确保在调试和检查时,Web服务方法的响应已正确更新为data.result。 感谢