Im using dropzone.js and loading it using ajax.
My menu ID = "#menu" The upload file should appear in "#div1"
The callback function is not working. I replaced Dropzone.discover by alert("test");
(document).ready(function() {
    $("#menu").click(function(){
    $("#div1").load("upload.php",null, function(){
        Dropzone.discover();
    });
Note: I tried the code below, but it didnt work.
$("#div1").load("upload.php", function(){
    Dropzone.discover();
});
                Dropzone. js is 'a light weight JavaScript library that turns an HTML element into a "dropzone"'. Users can drag and drop a file onto an area of the page, uploading to a server. If you would like to read more how all of this works skim through the Dropzone.
To access all files in the dropzone, use myDropzone. files . If you do not need a dropzone anymore, just call . disable() on the object.
I had a problem getting a Dropzone that was loaded via Ajax to work and discovered that adding the Dropzone.discover(); call fixed it for me.
You should define dropzone on #dive and add your events in init function of dropzone to change it's options related to each #menu. it's best way.
fore example:
var myDropzone = new Dropzone("#div1",{
    url: '/test.php',
    acceptedFiles: "image/*",
    addRemoveLinks: true,
    removedfile: function(file) {
        $.get('remove.php',function(data){
            var _ref;
            return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
        });
    },
    init: function() {
        var thisDropzone = this;
        $('body').on('click','a.menu',function(event){
            href = $(this).attr('href');
            thisDropzone.options.url = href;
        });
        $("body").on('click','#btnRemoveAll',function () {
                thisDropzone.removeAllFiles();
            }
        );
    }
});
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With