JQuery:如何使用dropzone.js将多个文件放入formData中,并通过ajax发送
JQuery : How to put multiple files into formData using dropzone.js and send it via ajax
我有一个问题试图上传我的多个文件。我有两个方法通过ajax发送到一个页面。一个是dropzone,另一个是XMLHttpRequest
。每次我通过点击按钮发送,它重复我的请求,只遵循第一个方法,这是dropzone,忽略我的XMLHttpRequest
。所以我试图找出方法来发送它绑定到一个formData,使它只有一个请求的文件在一起。
<form style="border:3px dashed #D9EDF7;" action="UploadImage"
class="dropzone dz-clickable"
id="my-awesome-dropzone" enctype="multipart/form-data">
<div class="dz-message">Drop files here or click to upload.
<br> <span class="note">(Selected files are not
automatically uploaded.)</span>
</div>
<div class="fallback">
<input name="file" id="filez" type="file" multiple/>
</div>
</form>
我Js Dropzone.autoDiscover = false;
var myDropzone = new Dropzone('#my-awesome-dropzone', {
url : '../ajax/ajax_add/ajax_addNEWContestant.php?
multipleImage=multiple_image&event_id='+event_id,
autoProcessQueue : false
});
$(document).on('click','#addnewContestant', function(e){
myDropzone.processQueue();
var formdata = new FormData();
formdata.append('file_addnew', file_addnew.files[0]);
//If there is a way, I just want to bind all the files from dropzone into formData
var data = new FormData();
for(var b=0; b<imageContainer.length; b++){
formdata.append('All_files_from_dropzone[], input_file.files[b]);
}
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);
beforeSend();
xhr = new XMLHttpRequest();
var url = '../ajax/ajax_add/ajax_addNEWContestant.php';
xhr.open('post', url+param, true);
});
Dropzone已经将其他表单字段与文件一起提交,因此您不需要自己做任何xhr工作
相关文章:
- 使用Codeigner通过JQueryAJAX发送FormData和上传文件
- 无法处理 PHP 服务器中由 FormData 发送的数据
- FormData()只发送对象类型的多文件
- 如何访问使用websocket发送的烧瓶中的formData?Flask SocketIO
- 浏览器强制发送multipart/formdata
- 在 Java 文件中处理从 Ajax 发送的 FormData
- 如何使用 ASP.NET 在服务器端发送 FormData 并对其进行处理
- 通过 Ajax 和 FormData 发送文件失败
- 通过 AJAX 将帖子变量添加到使用 FormData() 发送表单
- 如何将formData从Angular 2发送到nodejs
- 为什么我的formdata.append没有将键值对发送到服务器
- 如何使用FormData将文件发送到Nodejs,并让Node发回确认消息
- 将FormData发送到ajax时未捕获的TypeError非法调用
- 如何使用nervgh发送formData's Angular File Upload
- Laravel Ajax Input::all()在通过FormData发送时返回空
- 在FormData中发送整数
- FormData将布尔值作为字符串发送到服务器
- 如果在iOS的web应用中使用FormData发送,文件将转换为[Object Object]字符串&Android
- Javascript XMLHttpRequest FormData发送不工作
- 我如何使用xhr2和FormData发送文件数组?(Java + Spring)