我在将Dropzone.js与自己的ajax函数集成时遇到困难,我不知道在我的ajax函数中使用dropzone应该怎么做。
这是我自己的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');}
答案 0 :(得分:0)
您只需要相应地配置您的放置区。
使用sending事件,您可以执行以下操作:
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
});
}
});