Dropzone.js 个选项 - 无法让它们工作

Dropzone.js options - cannot get them to work

基于Dropozone.js FAQ 我尝试在上传成功时显示一条消息。

header 中的代码如下所示:

<script>
$(document).ready(function() {
    Dropzone.options.myDropzone = {
      init: function() {
        this.on("success", function(file, responseText) {
          var responseText = "TaDa!";
          file.previewTemplate.appendChild(document.createTextNode(responseText));
        });
      }
    };
)};
</script>

来自 html 部分的代码:

<form action="/file-upload" class="dropzone" id="my-dropzone"></form>

拖放上传工作正常,但我在 success 上没有收到想要的消息。

这是因为 dropzone 在设置选项之前初始化,为了避免这种情况,只需将 dropzone 选项放在 ready 函数之外。

<script>

    Dropzone.options.myDropzone = {
        init: function() {
            this.on("success", function(file, responseText) {
            var responseText = "TaDa!";
            file.previewTemplate.appendChild(document.createTextNode(responseText));
            });
        }
    };

    $(document).ready(function() {
        // Your other javascript
    )};

</script>

我也遇到了这个问题,在尝试@wallek876 提供的解决方案后,我仍然无法为 #Media_Dropzone 对象设置选项。最后我发现 Dropzone 无法找到 ID 中包含下划线的元素!!所以基本上将元素从 #Media_Dropzone 重命名为 #MediaDropzone 并且当然在这里实施接受的答案解决了我的问题。