简体   繁体   中英

Dropzone.js - nothing happens when click dropzone element

I'm trying add Dropzone component in a page and I'm having such a big pain with this component: no matter what I do, nothing happens when I click or drop file in the dropzone's element.

<form id="registerUserForm" onsubmit="return submitForm()" class="mt-5">

    <div id="dropzoneDiv" class="dropzone dz-clickable">
        <div class="dz-default dz-message">
            <span>Drop files here to upload</span>
        </div>
     </div>
        .
        .
        .
</form>

As you can see, I'm configuring Dropzone in javascript:

var dropzone=null;

$(document).ready(function () {
    Dropzone.autoDiscover = false;
    dropzone=$("#dropzoneDiv").dropzone({
        url: "/api/works/upload",
        acceptedFiles: 'image/*,video/*',
        autoProcessQueue: false,
        createImageThumbnails: true,
        addRemoveLinks: true
    });
});

function submitForm() {
    dropzone.processQueue();
    return false;
}     

The component is correctly rendered, however simple does not work:

在此处输入图片说明

Am I doing something wrong I didn't notice?

I found the solution by chance, the problem is with $(document).ready() sentence. If I remove this listener and use the dropzone configuration call directly, the component works correctly:

var dropzone = null;

Dropzone.autoDiscover = false;
dropzone = $("#dropzoneDiv").dropzone({
    url: "/api/works/upload",
    acceptedFiles: 'image/*,video/*',
    autoProcessQueue: false,
    createImageThumbnails: true,
    addRemoveLinks: true
});

function submitForm() {
    dropzone.processQueue();
    return false;
}

Try using JQuery 2.*, If you are using JQuery > 3

 var dropzone=null; $(document).ready(function () { Dropzone.autoDiscover = false; dropzone=$("#dropzoneDiv").dropzone({ url: "/api/works/upload", acceptedFiles: 'image/*,video/*', autoProcessQueue: false, createImageThumbnails: true, addRemoveLinks: true }); }); function submitForm() { dropzone.processQueue(); return false; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.1.1/min/dropzone.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.1.1/min/dropzone.min.js"></script> <form id="registerUserForm" onsubmit="return submitForm()" class="mt-5"> <div id="dropzoneDiv" class="dropzone dz-clickable"> <div class="dz-default dz-message"> <span>Drop files here to upload</span> </div> </div> </form> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM