【发布时间】:2016-09-28 18:55:49
【问题描述】:
我正在尝试使用 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
});
});
【问题讨论】:
-
您正在将 Dropzone 添加到单击事件内的表单元素中,这意味着每次单击该项目时,此代码都会运行。这会在您第一次单击之后为您提供错误消息,因为正如它所说,Dropzone 已经添加到目标元素中。您必须 a) 在
domready上而不是单击时将 dropzone 添加到表单中,或者 b) 如果您在代码中的其他位置动态添加新字段,则仅将其添加到字段本身,而不是表单。跨度> -
如果我使用 a.我的输入字段值不会发送。只有来自 dropzone 的文件,我如何实现文件和输入字段的值相同。
-
您可以使用带有
multiple属性集的<form>包括<input type="file" multiple>元素。用户可以在<input type="file" multiple>元素中选择多个文件,然后用户可以提交表单,该表单应包含<form>元素中的文件和其他输入字段。
标签: javascript jquery dropzone.js