Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  17] [ 6]  / answers: 1 / hits: 67052  / 7 Years ago, thu, february 2, 2017, 12:00:00

I can't figure out how to get JSONresponse after uploading a file using Dropzonejs.



I have just this:



<script src={% static dropzone/dropzone.js %}></script>

<form id=id_dropzone class=dropzone action=/ajax_file_upload_handler/
enctype=multipart/form-data method=post></form>


I think it is not possible without manually initializing dropzone so I changed it to:



$(#id_dropzone).dropzone({
maxFiles: 2000,
url: /ajax_file_upload_handler/,
success: function (file, response) {
console.log(response);
}
});


<form id=id_dropzone class= action=
enctype=multipart/form-data method=post></form>


Which return Uncaught Error: No URL provided.



How can I initialize dropzone so I can add an options like maxFiles, maxSize and get JSON response?


More From » jquery

 Answers
11

No URL provided happens when a Dropzone gets attached to an object without either:



  • an action attribute on a form that tells dropzone where to post

  • a configuration for specific dropzone


My bet is, that you have a race condition, where Dropzone attaches itself to an element before you configured it. Make sure that your configuration is either directly after the JS import, or that you set Dropzone.autoDiscover = false; and instantiate the Dropzone explicitly.


Take a look over here for more information.


<script src="{% static "dropzone/dropzone.js" %}"></script>

<script type="text/javascript">

Dropzone.autoDiscover = false;

$(document).ready(function () {
$("#id_dropzone").dropzone({
maxFiles: 2000,
url: "/ajax_file_upload_handler/",
success: function (file, response) {
console.log(response);
}
});
})

</script>

<form id="id_dropzone"
class="dropzone"
action="/ajax_file_upload_handler/"
enctype="multipart/form-data"
method="post">
</form>

[#59102] Tuesday, January 31, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kylie

Total Points: 121
Total Questions: 84
Total Answers: 91

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
;