Dropzone js 不会触发 ajax 调用
Dropzone js wont trigger an ajax call
您好,我目前正在我的 Dropbox 的 Dropzone 中工作 API 我想知道为什么我的 dropzone 不能调用我的 ajax 请求?我将我的 ajax 请求放在我的 init:function
中并认为它会起作用,因为我的按钮功能起作用了。我想知道是否存在逻辑错误,或者我只是放错了我的 ajax 请求..
<form id="files" action="/" class="dropzone" name="files[]" ></form>
<input type = "button" id = "btnsubmit" value = "Submit"></input>
这是我的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 放入处理过程中,但我认为它没有读取我的 ajax 请求
我不知道 Dropbox api 是如何工作的,但这是您可以使用 Dropzone 做的事情。但是你必须在服务器端处理文件。如果您有服务器 (XAMPP),您可以尝试将文件上传到那里,然后向您的保管箱发出请求 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){
});
}
将你的 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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://brightscreentv.net/WAYW/js/dropzone.js"></script>
<div id='drop_zone'>
<form action="https://content.dropboxapi.com/2/files/upload" class='dropzone' id='MyDropzone'></form>
</div>
您好,我目前正在我的 Dropbox 的 Dropzone 中工作 API 我想知道为什么我的 dropzone 不能调用我的 ajax 请求?我将我的 ajax 请求放在我的 init:function
中并认为它会起作用,因为我的按钮功能起作用了。我想知道是否存在逻辑错误,或者我只是放错了我的 ajax 请求..
<form id="files" action="/" class="dropzone" name="files[]" ></form>
<input type = "button" id = "btnsubmit" value = "Submit"></input>
这是我的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 放入处理过程中,但我认为它没有读取我的 ajax 请求
我不知道 Dropbox api 是如何工作的,但这是您可以使用 Dropzone 做的事情。但是你必须在服务器端处理文件。如果您有服务器 (XAMPP),您可以尝试将文件上传到那里,然后向您的保管箱发出请求 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){
});
}
将你的 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;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://brightscreentv.net/WAYW/js/dropzone.js"></script>
<div id='drop_zone'>
<form action="https://content.dropboxapi.com/2/files/upload" class='dropzone' id='MyDropzone'></form>
</div>