gpt4 book ai didi

javascript - 如何将附加数据发送到 jQuery 文件上传插件?

转载 作者:搜寻专家 更新时间:2023-11-01 05:24:48 24 4
gpt4 key购买 nike

这看起来很愚蠢,但我似乎无法理解文档。我说的是 This文件上传插件。

现在根据文档有一个选项:

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 } ]

我不明白我应该用它做什么。

这是我初始化插件的方式:

$('#add_image_upload').fileupload({
dataType: 'json',
sequentialUploads: true,
formData : getDate
});

这是我对该功能的尝试:

 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;
}

最佳答案

尝试将您的数据转换为对象 - 使用他们在示例中显示的内容

$('#add_image_upload').fileupload({
dataType: 'json',
sequentialUploads: true,
formData : {name:'thedate',value:getDate}
});

然后添加更多的参数

           //name of param  // value
formData : [{name:'thedate',value:getDate},{name:'thedate2',value:'seconddate'},etc..]

Example:

[ { name: 'a', value: 1 }, { name: 'b', value: 2 } ]

thedate 更改为您想要命名的参数

虽然这听起来像一个简单的对象应该可以正常工作

           //name:value
formData : {thedate:getDate}

关于javascript - 如何将附加数据发送到 jQuery 文件上传插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13034468/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com