【问题标题】:Dropzone.js - remove preview file if upload failsDropzone.js - 如果上传失败删除预览文件
【发布时间】:2017-06-14 04:27:15
【问题描述】:

我的放置区有问题,

$(".js-example-basic-multiple").select2();
Dropzone.options.dropZone = {
    //options here
    maxFilesize: 2,
    addRemoveLinks: true,
    removedfile: function(file) {
        var name = file.name;        
        $.ajax({
        type: 'POST',
        url: host+'upload/unfile',
        data: "id="+name,
        dataType: 'html'
        });
        var _ref;
        return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;        

        //console.log();
    },
    init: function() {
        this.on("maxfilesexceeded", function(file){
            alert("No more files please!");
        });
    }
}

我的问题是,当文件上传失败时,它仍然显示预览图像,所以我需要在这些文件上传失败时自动删除该文件,我该怎么做??

【问题讨论】:

  • Tq for smarx,抱歉我的英语不好

标签: dropzone.js


【解决方案1】:

我认为,如果我理解正确,您可以使用以下代码删除图像:

Dropzone.options.dropZone = {
    ...
    , error: function(file, message, xhr) {
        $(file.previewElement).remove();
    },
    ...
}

请再次阅读文档。 此代码来自文档:

myDropzone.on("error", function(file) {
  myDropzone.removeFile(file);
});

如果它适用于您的情况,请告诉我。

【讨论】:

  • 只有后者对我有用。第一个只是删除预览。然后我的dropzone,drop-area缩小了。
【解决方案2】:

当连接错误为“xhr.ontimeout”时,函数“error:”不运行。

我需要(粘贴到“init:”旁边):

sending: function(file, xhr, formData) {
  //Execute on case of timeout only
  xhr.ontimeout = function(e) {
   alert('connection interrupted');
 };
}

【讨论】:

    猜你喜欢
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 2015-04-08
    • 2013-12-25
    相关资源
    最近更新 更多