javascript - 如何获取 Dropzone.js 的返回值?

标签 javascript html file-upload dropzone.js

我刚刚实现了 Dropzone.js使我的网站上的文件上传更容易。文件上传正常,上传完成后我给文件一个 ID 并将此 ID 返回给浏览器。

这工作正常,除了我不知道如何捕获从服务器返回的 ID。在 this SO answer我找到了一些应该可以做到这一点的代码,但它对我不起作用。我现在的代码粘贴在下面。

有人知道我怎样才能得到服务器返回的值吗?欢迎所有提示!

<!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的源码,好像有很多可以监听的事件

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"
]

这里的“成功”事件似乎是合适的。

一个好的起点是将事件监听器绑定(bind)到您的 dropzone 并查看您从此类事件中获得的数据。

$('#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);
});

关于javascript - 如何获取 Dropzone.js 的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26421731/

相关文章:

javascript - 在 Node 中插入新的 mongo 文档时保存不带 ObjectID 部分的 _id

php - 需要按日期水平显示记录

c# - ASP.NET MVC/WEB API 文件上传 : Memory not being deallocated after upload

node.js - Ext.Direct 文件上传 - 回调 - 错误 "Blocked a frame with origin"

gwt - FileUpload 的过滤器和处理程序

javascript - 不同页面的多次点击事件

javascript - Typescript 在 valueAsDate 上抛出错误

javascript - 我无法在 html 中调用 js 文件中的函数

html - 如何在页面中放置 flash (.swf)?

html - 如何让表单字段在页面加载时立即变为事件状态?