我正在使用 jQuery 文件 uploader 插件和 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 会这样做吗?谢谢
最佳答案
您使用的是基本插件吗?我曾经和我遇到过同样的问题并与之斗争了一天才意识到我没有包含 jquery.iframe-transport.js 插件:
<script src="js/jquery.iframe-transport.js"></script>
参见文档 here .
哦!并感谢您关于将“authenticity_token”键值对包含为“formData”的片段 - 这帮助我摆脱了 Rails 3 警告“警告:无法验证 CSRF token 真实性”
关于javascript - jQuery File Uploader IE9 不在上传时发布任何参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12699617/