[英]How can I use Dropzone.js in my own function
I am having difficulties integrating Dropzone.js with my own ajax function, I don't know what I should do to use dropzone inside my ajax function. 我在将Dropzone.js与我自己的ajax函数集成时遇到了困难,我不知道在我的ajax函数中使用dropzone应该怎么做。
This is my own ajax function code : 这是我自己的ajax功能代码:
function _ajaxForm(formHandler){
var action = $(formHandler).attr('action');
$.post(action, $(formHandler).serialize(), function(data){
// I want to submit my fields and my form upload using this function
}, 'json');}
You just need to configure your dropzone accordingly. 您只需要相应地配置dropzone。
Using the sending event you could do something like this: 使用发送事件,您可以执行以下操作:
Dropzone.options.myAwesomeDropzone = {
// Some default configurations
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
// Additional configurations needed for your ajax call
url: "insertyoururlhere",
init: function () {
this.on("error", function (error, message) {
//do something to handle the error
});
this.on("success", function (success, response) {
//do something
});
this.on("sending", function (file, xhr, formData) {
//add any form data that you would have in your ajax function eg:
//formData.append("id", 123);
});
this.on("complete", function () {
this.removeAllFiles(true);
//do something
});
}
});
See this , this and this answer which might also help. 看到这个 , 这个和这个答案也可能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.