我正在使用以下jQuery文件上传插件:
https://github.com/blueimp/jQuery-File-Upload/wiki/Options
我需要指定额外的表单数据,文档中提到有一个选项可以实现,但是我遇到了JS错误“Uncaught SyntaxError: Unexpected identifier”,并且没有FormData的示例,这让我很难解决问题。
以下是我的代码:
$(function () {
$('.upload').fileUploadUI({
uploadTable: $('.upload_files'),
downloadTable: $('.download_files'),
buildUploadRow: function (files, index) {
var file = files[index];
return $(
'<tr>' +
'<td>' + file.name + '<\/td>' +
'<td class="file_upload_progress"><div><\/div><\/td>' +
'<td class="file_upload_cancel">' +
'<div class="ui-state-default ui-corner-all ui-state-hover" title="Cancel">' +
'<span class="ui-icon ui-icon-cancel">Cancel<\/span>' +
'<\/div>' +
'<\/td>' +
'<\/tr>'
);
},
buildDownloadRow: function (file) {
return $(
'<tr><td>' + file.name + ' ' + file.type + ' ' + file.size + '<\/td><\/tr>'
);
},
formData:
[
{
name: '_http_accept'
value: 'application/javascript'
},
{
name: '<%= session_key_name %>'
value: encodeURIComponent('<%= u cookies[session_key_name] %>'),
},
{
name: 'authenticity_token'
value: encodeURIComponent('<%= u form_authenticity_token %>')
}
]
});
});