weixin_33724059 2014-02-25 14:04 采纳率: 0%
浏览 201

Dropzone.js和Ajax

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();
});
  • 写回答

2条回答 默认 最新

  • ??yy 2014-08-31 07:30
    关注

    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();
                }
            );
    
        }
    });
    
    评论

报告相同问题?