根据这个问题,我正在使用 Malsup 的 jQuery Form Plugin 异步上传文件。
它非常适合上传文件,但我有兴趣随文件一起发送其他数据(例如上传文件的人的用户名。
有没有办法添加这些额外的数据?
这是用于上传文件的当前代码:
(假设<input type=file/>
HTML 表单中的标准带有id=upload
)
// site/js/app.js
var app = app || {};
(function($){
})(jQuery);
// prepare the form when the DOM is ready
$(document).ready(function() {
var options =
{
url: 'http://localhost:3000/file_upload',
dataType: 'json',
success: function(response, statusText, xhr, form)
{
alert('success!');
};
$("#upload").ajaxForm(options);
});