Why is my dropzone javascript form not working?

吃可爱长大的小学妹 提交于 2019-12-05 03:47:24
aaramans

Even I faced the same problem. After some minutes of research, I found that we need to specify url for elements when not using form. But in your case you have used form tag for implementing dropzone, so it requires an action like..

<form action="some_target_url" class="dropzone"></form>

this worked for me..try this.

I found this in the website of dropzone.js in options table(scroll down)

<form class="dropzone" id="myDropzone" action="url.php"> in HTML code (or even without specifying any id) is good. That said :

Url can be specified in javascript in options - Ways of doing it :

1) if autodiscover is let to true (default) Dropzone.options.myDropzone = { url : "url.php",...
With JS the id of the form must be declared in form : id="mydropzone" or #my-dropzone
Having class="dropzone" is not enough.
Note : autodiscover must be declared just after and before dom ready.

2) if Dropzone.autoDiscover = false :
var myDropzone = new Dropzone("#myDropzone", { url: "url.php",... // JS : Dropzone class
or
$("#myDropzone").dropzone({ url: "url.php",... // JS : jquery style
Note : you can of course use another id, code will be Dropzone.options.myOtherId =... , $("#myOtherId").dropzone... etc.

warning : jQuery document ready callback function and JQUERY 3 :
"Uncaught Error: No URL provided." can happen still happen in one condition (wich brought me here) :


Scenario 1 :
loading dropzone.js and jQuery 2 in autodiscover let to true
then, in jQuery document ready : Dropzone.options.myDropzone = { url : "url.php",...
--> all is fine


Scenario 2 :
Switching to jQuery 3 without any other change : "Uncaught Error: No URL provided."
--> nothing work

It seems to be because of the new way jQuery handle doc ready : https://jquery.com/upgrade-guide/3.0/#breaking-change-document-ready-handlers-are-now-asynchronous

Solution with jQuery 3 :
1) let autodiscover to true and put ALL code OUTSIDE jQuery doc ready
or
2) set autodiscover to false BEFORE doc ready and declare options (url among others) via Javascript IN doc ready

INFOS : https://github.com/enyo/dropzone/issues/1423

<form action="files" class="dropzone">
    <div class="fallback">
        <input type="file" name="file" multiple />
    </div>
</form>

Same problem - easy solution -> I did not specify dropzone URL in his configuration.

        $("#dZUpload").dropzone({
            url: "my-upload-url",
        });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!