Dropzone js不会触发ajax调用

嗨,我目前正在Dropzone中使用我的Dropbox API,我想知道为什么我的dropzone无法调用我的ajax请求? 我把我的ajax请求放在我的init:function并认为它会起作用,因为我的按钮的function工作。 我想知道是否存在逻辑错误或者我错放了我的ajax请求。

  

这是我的js

 Dropzone.options.files = { autoProcessQueue : false, dictDefaultMessage: "Drop files or click here to upload file(s) ...", init : function() { function uploadfiles(upl) { var files = upl.target.files; var url = "https://content.dropboxapi.com/2/files/upload"; for (var i = 0, file_name; file_name = files[i]; i++) { $.ajax({ url: url, type: 'post', data: file_name, processData: false, contentType: 'application/octet-stream', headers: { "Authorization": "ACCESTOKEN", "Dropbox-API-Arg": '{"path": "/' + file_name.name + '","mode": "add"}' }, success: function (data) { this.on("processing", function(file) { this.options.url = url; alert('Success Upload'); }); console.log(data); }, error: function (data) { console.log(data); } }) } files = this; this.on("drop", function(event) { console.log(files.files); }); Dropzone.autoDiscover = false; $('#btnsubmit').click(function(){ files.processQueue(); }); } document.getElementById('files').addEventListener('change', uploadfiles, false); } } 

我试图把我的ajax放在里面,如果我的处理,但我认为它doesent阅读我的ajax请求

Pu你的this.on("drop", function(event)函数在Init函数内部并调用你的ajax方法上传这个drop函数里面的图片请在下面的代码片段中找到

 Dropzone.options.MyDropzone = { var FormActionURL; init : function() { myDropzone = this; this.on("drop", function(event) { alert("Form Action URL:- "FormActionURL); //Put your ajax call here for upload image console.log(myDropzone.files); }); } }; 
 #drop_zone { width: 50%; border: 2px dashed #BBB; border-radius: 5px; padding: 25px; text-align: center; color: #BBB; } 
   

我不知道dropbox api是如何工作的,但是这是你可以用Dropzone做的。 但是你必须在服务器端处理该文件。 如果你有一台服务器(XAMPP),你可以尝试在那里上传文件,然后向你的dropbox api发出请求。

 init: function(){ /* Called once the file has been processed. It could have failed or succeded */ this.on("complete", function(file){ }); /* Called after the file is uploaded and sucessful */ this.on("sucess", function(file){ }); /* Called before the file is being sent */ this.on("sending", function(file){ }); }