jQuery File Uploader IE9不会在上传中发布任何参数 [英] jQuery File Uploader IE9 Not posting any params on Upload

查看:186
本文介绍了jQuery File Uploader IE9不会在上传中发布任何参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的jQuery文件上传插件随着轨3.插件在这里:

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



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



在chrome中的示例文章:

 开始PUT/ api / 1 / settings / ajax_photo_upload为10.0.1.3于2012-10-02 15:39:20 -0700 
处理由ApiV1 :: SettingsController#ajax_photo_upload如JS
参数:{ 照片=>#< ActionDispatch :: HTTP :: UploadedFile的:0x007f9e4bac2e48 @ original_filename = xxxxx.jpeg,@ CONTENT_TYPE = image / jpeg,@ headers =Content-Disposition:form-data; name = \user [photo] \; filename = \xxxxx.jpeg\\r\\\
Content-Type:图像/ jpeg\r\\\
,@tempfile =#<文件:在/ var /文件夹/ 3X / k1yb0r4s07q1jm82kq93ch180000gn / T / RackMultipart20121002-3633-sxsbtu>>}, update_type=> 中一般}

然而在IE9中,它并没有发送任何东西:

 开始PUT/ api / 1 / settings / ajax_photo_upload为10.0.1.10于2012-10-02 15:39:31 -0700 
Proc咝声由ApiV1 :: SettingsController#ajax_photo_upload为JS

下面是我实现的:

  $( '输入[类型= 文件]')文件上传({
网址:/ API / 1 /设置/ ajax_photo_upload ,
FORMDATA:[{
名称: 'authenticity_token',
值为:$( '元[名称= CSRF令牌]')ATTR( '内容')
$ b type:'PUT',
dataType:'json',
add:function(e,data){
data.submit();
}
});

html

 < input name =user [photo]type =fileaccept =image / *> 

为什么IE会这样做?谢谢

解决方案

您是否使用基本插件?我和我有同样的问题,并争取了一天,才意识到我没有包括jquery.iframe-transport.js插件:

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

查看文档这里



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

I'm using the jQuery file uploader plugin along with rails 3. Plugin here:

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

I'm using the plugin to allow a user to upload a profile photo. The solution so far works with Chrome, Safari and Firefox. However on IE it fails. When you select a file in IE, the plugin posts to the server but there are no params, it's an empty post.

Example post in 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"}

However in IE9, it doesn't send over anything:

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

Here is my implementation:

$('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/*" >

Any ideas why IE would be doing this? Thanks

解决方案

Are you using the basic plugin? I was and I had the same issue and battled with it for a day only to realize I hadn't included the jquery.iframe-transport.js plugin:

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

See documentation here.

Oh! and thanks for your snippet about including the 'authenticity_token' key-value pair as 'formData' - that helped me get rid of the rails 3 warning "WARNING: Can't verify CSRF token authenticity"

这篇关于jQuery File Uploader IE9不会在上传中发布任何参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆