【问题标题】:Dropzone delete uploaded images database and serverDropzone 删除上传的图片数据库和服务器
【发布时间】:2018-05-14 15:49:00
【问题描述】:

我正在使用 dropzone。现在当拖拽成功保存图片时。

单击删除时,它会删除我们期望的文件。

但是当页面加载时,以前的文件会显示并点击删除。它不会删除文件。我不知道为什么?我应该添加什么?或删除?还是改变?

这些是我的代码:

var total_photos_counter = 0;
    var dropZone = new Dropzone('#my-dropzone',{
    uploadMultiple: true,
    parallelUploads: 2,
    maxFilesize: 4,
    addRemoveLinks: true,
    dictRemoveFile: 'Remove',
    dictFileTooBig: 'Limit: 4MB',
    timeout: 10000,
    init: function () {
        this.on("removedfile", function (file) {
            $.post({
                url: '/images-delete',
                data: {id: file.name, _token: $('[name="_token"]').val()},
                dataType: 'json',
                success: function (data) {
                    total_photos_counter--;
                    $("#counter").text("# " + total_photos_counter);
                }
            });
        });
    },
    success: function (file, done) {
        total_photos_counter++;
        $("#counter").text("# " + total_photos_counter);
    }
});



for (i = 0; i < existingFiles.length; i++) {
    dropZone.emit("addedfile", existingFiles[i]);
    dropZone.emit("thumbnail", existingFiles[i], existingFiles[i].url);
    dropZone.emit("complete", existingFiles[i]);
}

提前致谢。

【问题讨论】:

    标签: javascript ajax file dropzone.js dropzone


    【解决方案1】:

    你应该删除

    `for (i = 0; i < existingFiles.length; i++) {
        dropZone.emit("addedfile", existingFiles[i]);
        dropZone.emit("thumbnail", existingFiles[i], existingFiles[i].url);
        dropZone.emit("complete", existingFiles[i]);
    }`
    

    因为此代码在页面加载两次时运行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-21
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      相关资源
      最近更新 更多