admin管理员组文章数量:1278796
This would seem stupid but i can't seem to understand the documentation. I'm talking about This plugin for file upload.
Now according to the documentation there's an option :
formData
Additional form data to be sent along with the file uploads can be set using this option, which accepts an array of objects with name and value properties, a function returning such an array, a FormData object (for XHR file uploads), or a simple object. The form of the first fileInput is given as parameter to the function.
Note: Additional form data is ignored when the multipart option is set to false.
Type: Array, Object, function or FormData Default: A function returning the form fields as serialized Array:
function (form) { return form.serializeArray(); }
Example:
[ { name: 'a', value: 1 }, { name: 'b', value: 2 } ]
Which i fail to understand what i'm suppoused to do with that.
This is how i initialize the plugin :
$('#add_image_upload').fileupload({
dataType: 'json',
sequentialUploads: true,
formData : getDate
});
And this is my attempt to the function :
function getDate(){
//if user didn't selected a date
if(!selectedDate || selectedDate=="undefined"){
selectedDate = "1/1/"+$('#timeline').html();
}
var date= new Array(selectedDate);
return date;
}
This would seem stupid but i can't seem to understand the documentation. I'm talking about This plugin for file upload.
Now according to the documentation there's an option :
formData
Additional form data to be sent along with the file uploads can be set using this option, which accepts an array of objects with name and value properties, a function returning such an array, a FormData object (for XHR file uploads), or a simple object. The form of the first fileInput is given as parameter to the function.
Note: Additional form data is ignored when the multipart option is set to false.
Type: Array, Object, function or FormData Default: A function returning the form fields as serialized Array:
function (form) { return form.serializeArray(); }
Example:
[ { name: 'a', value: 1 }, { name: 'b', value: 2 } ]
Which i fail to understand what i'm suppoused to do with that.
This is how i initialize the plugin :
$('#add_image_upload').fileupload({
dataType: 'json',
sequentialUploads: true,
formData : getDate
});
And this is my attempt to the function :
function getDate(){
//if user didn't selected a date
if(!selectedDate || selectedDate=="undefined"){
selectedDate = "1/1/"+$('#timeline').html();
}
var date= new Array(selectedDate);
return date;
}
Share
Improve this question
asked Oct 23, 2012 at 15:53
eric.itzhakeric.itzhak
16.1k27 gold badges94 silver badges146 bronze badges
2 Answers
Reset to default 7try turning your data into in object - with what they showed in their example
$('#add_image_upload').fileupload({
dataType: 'json',
sequentialUploads: true,
formData : {name:'thedate',value:getDate}
});
Then to add more params
//name of param // value
formData : [{name:'thedate',value:getDate},{name:'thedate2',value:'seconddate'},etc..]
Example:
[ { name: 'a', value: 1 }, { name: 'b', value: 2 } ]
Changing thedate
with whatever you want to name the param
Though it sounds like a simple object should work fine
//name:value
formData : {thedate:getDate}
Do you have multipart
set to false
on your form? Also, ensure the format of what you're sending back is acceptable.
Try hard-coding the following line and sending back the info:
new dateobject = { "date": "1/1/2012" }
本文标签: javascriptHow to send additional data to jQuery File Upload PluginStack Overflow
版权声明:本文标题:javascript - How to send additional data to jQuery File Upload Plugin? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741222938a2361312.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论