javascript jQuery 文件上传不提交额外参数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15647503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery file upload doesn't submit extra parameters
提问by John Livermore
I need to use the formData parameter available in the jQuery File Upload control to send additional data to the server on submit. The default implementation for formData is to invoke a function that grabs all controls in the form and serializes them to an array (using the jQuery serializeArray() method).
我需要使用 jQuery 文件上传控件中可用的 formData 参数在提交时将附加数据发送到服务器。formData 的默认实现是调用一个函数,该函数获取表单中的所有控件并将它们序列化为一个数组(使用 jQuery serializeArray() 方法)。
I have controls in my form, but when the file is uploaded, I am not getting any additional data. When I inspect via Fiddler, there is nothing in the request that shows these form fields are being submitted.
我的表单中有控件,但是当文件上传时,我没有得到任何额外的数据。当我通过 Fiddler 检查时,请求中没有任何内容显示正在提交这些表单字段。
Is there something additional that needs to be done to get these to submit?
是否需要做一些额外的事情来提交这些?
Btw, these two links discuss formData...
顺便说一句,这两个链接讨论了 formData ...
https://github.com/blueimp/jQuery-File-Upload/wiki/Submit-files-asynchronouslyhttps://github.com/blueimp/jQuery-File-Upload/wiki/Options...for this one search the page for formData.
https://github.com/blueimp/jQuery-File-Upload/wiki/Submit-files-asynchronously https://github.com/blueimp/jQuery-File-Upload/wiki/Options...为此搜索formData 的页面。
For what its worth, the multipart
option is set to true.
就其价值而言,该multipart
选项设置为 true。
回答by Yasser Shaikh
I also needed to pass an extra parameter and here is what i used :
我还需要传递一个额外的参数,这是我使用的:
$('#fileupload').fileupload({
formData: {
param1: 'test'
,param2: "value2"
,param3: "yasseshaikh"
}
});
The formData optioncan be used to set additional form data programmatically.
该FORMDATA选项可用于编程方式设置附加的形式的数据。
回答by cp100
Complete code (I modified the answer provided by Yasser)
完整代码(我修改了Yasser提供的答案)
Add these code into jquery.fileupload.js
将这些代码添加到 jquery.fileupload.js
submit: function (e, data) {
$('#fileupload').fileupload({
formData: {
param1: 'test'
,param2: "value2"
,param3: "yasseshaikh"
}
});
},
回答by ffffff01
If the blueimp plugin isn't a requirement I would really recommend the jquery malsup form.
如果不需要 blueimp 插件,我真的会推荐 jquery malsup 表单。
You can use a regular multipart form and just create a regular file input field along with other input fields of your own choice and everything is submitted as usual.
您可以使用常规的多部分表单,只需创建一个常规文件输入字段以及您自己选择的其他输入字段,然后一切都会照常提交。
Reference: http://www.malsup.com/jquery/form/
参考:http: //www.malsup.com/jquery/form/
Code sample:
代码示例:
$('#myForm2').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
回答by user2516513
You have to bind Your data to fileupload. Look at this question
Blueimp jQuery file upload, passing extra form data
您必须将您的数据绑定到文件上传。看这个问题
Blueimp jQuery文件上传,传递额外的表单数据