admin管理员组

文章数量:1406308

Based on Dropozone.js FAQ I have tried to display a message on successful upload.

Code from the header looks like:

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

And code from the html section:

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

Drag and drop upload works fine but I'm not getting desired message on success.

Based on Dropozone.js FAQ I have tried to display a message on successful upload.

Code from the header looks like:

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

And code from the html section:

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

Drag and drop upload works fine but I'm not getting desired message on success.

Share Improve this question asked Sep 15, 2016 at 1:47 JackTheKnifeJackTheKnife 4,1849 gold badges67 silver badges134 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

This is because dropzone initializes before the options are set, to avoid this just place the dropzone options outside the ready function.

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

I had this problem too and after trying the solution @wallek876 provided I was still unable to set options for the #Media_Dropzone object. finally I've found that Dropzone is unable to find elements with ID's in which contain underscores!! so basically renaming the element from #Media_Dropzone to #MediaDropzone and of-course implementing the accepted answer here solved my problem.

本文标签: javascriptDropzonejs optionscannot get them to workStack Overflow