我正在尝试使用dropzone从输入字段中发送多个有价值的文件。不幸的是我收到了一个错误,说dropzone已经附加了。
这是我的代码
$(document).on('click','#addContestant',function(e){
e.preventDefault();
var random_gender = $('#randomGender').val();
var contestant_name = $('#contestant_name').val();
var contestant_lastName = $('#contestant_lastName').val();
var conAge = $('#conAge').val();
var hAddress = $('#hAddress').val();
var email_add = $('#email_add').val();
var conContactNum = $('#conContactNum').val();
var conDesc = $('#conDesc').val();
var hidden_gender = $('#hidden_gender').val();
var conId_hidden = $('#conId_hidden').val(); // the contestant prima id
var param = "?event_id="+encodeURIComponent(event_id)+
"&contestant_name="+encodeURIComponent(contestant_name)+
"&contestant_lastName="+encodeURIComponent(contestant_lastName)+
"&conAge="+encodeURIComponent(conAge)+
"&hAddress="+encodeURIComponent(hAddress)+
"&email_add="+encodeURIComponent(email_add)+
"&conContactNum="+encodeURIComponent(conContactNum)+
"&conDesc="+encodeURIComponent(conDesc)+
"&conId_hidden="+encodeURIComponent(conId_hidden)+
"&hidden_gender="+encodeURIComponent(hidden_gender)+
"&random_gender="+encodeURIComponent(random_gender)+
"&multipleImage="+encodeURIComponent(multipleImage);
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone('form#my-awesome-dropzone', {
url : '../ajax/ajax_add/ajax_addNEWContestant.php?'+param,
maxFilesize: 3.0,
maxFiles: 4,
parallelUploads: 10000,
uploadMultiple: true,
autoProcessQueue: false
});
});
答案 0 :(得分:0)
克里斯·贝克是对的,在这里你要在同一个元素上附加多个Dropzone,谁将失败。
尝试初始化dropzone并使用事件'发送'。
// Dropzone config
Dropzone.autoDiscover = false;
// To run when dom is ready
$(document).ready(function(){
// Manual Dropzone init
var myDropzone = new Dropzone('form#my-awesome-dropzone', {
url : '../ajax/ajax_add/ajax_addNEWContestant.php',
maxFilesize: 3.0,
...
});
// Add dynamic event on sending
myDropzone.on('sending', function(file, xhr, formData){
// Fetch values to send
var contestant_name = $('#contestant_name').val();
...
// Add it to request data send by Dropzone
formData.append('event_id', encodeURIComponent(event_id));
formData.append('contestant_name', encodeURIComponent(contestant_name));
...
});
});
或直接在初始化
// Dropzone config
Dropzone.autoDiscover = false;
// To run when dom is ready
$(document).ready(function(){
// Manual Dropzone init
var myDropzone = new Dropzone('form#my-awesome-dropzone', {
url : '../ajax/ajax_add/ajax_addNEWContestant.php',
maxFilesize: 3.0,
...
sending: function(file, xhr, formData){
// Fetch values to send
var contestant_name = $('#contestant_name').val();
...
// Add it to request data send by Dropzone
formData.append('event_id', encodeURIComponent(event_id));
formData.append('contestant_name', encodeURIComponent(contestant_name));
...
}
});
});