如何获得Dropzone.js返回值? [英] How to get the Dropzone.js return value?
问题描述
我刚刚实施了 Dropzone.js ,使我的网站上的文件上传更容易。文件上传正常,上传完成后,我给该文件一个id,并将此ID返回给浏览器。
I just implemented Dropzone.js to make file uploads on my website easier. The file uploads fine, and after it finished uploading I give the file an id and return this id to the browser.
这个工作正常,除了我没有知道如何捕捉从服务器返回的ID。在这个SO答案中,我发现了一些应该这样做的代码,但它不适用于我。我现在的代码粘贴在下面。
This works fine, except for that I don't know how to catch the id that gets returned from the server. In this SO answer I found some code that should supposedly do that, but it doesn't work for me. The code I have now is pasted below.
有人知道我如何获得服务器返回的值吗?欢迎所有提示!
Does anybody know how I can get the value that is returned by the server? All tips are welcome!
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/static/js/external/dropzone.min.js"></script>
<link href="/static/css/external/dropzone.css" rel="stylesheet">
<script type="text/javascript">
$(function() {
Dropzone.options.uiDZResume = {
success: function(file, response){
console.log('WE NEVER REACH THIS POINT.');
alert(response);
}
};
});
</script>
</head>
<body>
<form action="/doc"
class="dropzone"
id="my-awesome-dropzone"></form>
</body>
</html>
推荐答案
查看dropzone.js的源代码,似乎有很多你可以听的事件。
Looking at the source code of dropzone.js, it seems that there is a lot of events you can listen to.
events: [
"drop"
"dragstart"
"dragend"
"dragenter"
"dragover"
"dragleave"
"addedfile"
"removedfile"
"thumbnail"
"error"
"errormultiple"
"processing"
"processingmultiple"
"uploadprogress"
"totaluploadprogress"
"sending"
"sendingmultiple"
"success"
"successmultiple"
"canceled"
"canceledmultiple"
"complete"
"completemultiple"
"reset"
"maxfilesexceeded"
"maxfilesreached"
]
这里的成功事件似乎是合适的。
Here the "success" event seems to be appropriate.
一个好的起点是将一个事件监听器绑定到你的dropzone并查看哪些数据你得到这样的事件。
A good starting point would be to bind an event listener to your dropzone and see what data you get on such event.
$('#my-awesome-dropzone').on('success', function() {
var args = Array.prototype.slice.call(arguments);
// Look at the output in you browser console, if there is something interesting
console.log(args);
});
这篇关于如何获得Dropzone.js返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!