Dropzone.js - 如果上传失败则删除预览文件
Dropzone.js - remove preview file if upload fails
我的拖放区有问题,
$(".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!");
});
}
}
我的问题是,当文件上传失败时,它仍然显示预览图像,所以我需要在这些文件上传失败时自动删除该文件,我该怎么做??
我想,如果我没理解错的话,你可以用这个代码删除图片:
Dropzone.options.dropZone = {
...
, error: function(file, message, xhr) {
$(file.previewElement).remove();
},
...
}
再读一遍文档。
此代码来自文档:
myDropzone.on("error", function(file) {
myDropzone.removeFile(file);
});
如果它适用于您的情况,请告诉我。
当连接错误为 "xhr.ontimeout" 时,函数 "error:" 不会 运行。
我需要(粘贴到 "init:" 旁边):
sending: function(file, xhr, formData) {
//Execute on case of timeout only
xhr.ontimeout = function(e) {
alert('connection interrupted');
};
}
我的拖放区有问题,
$(".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!");
});
}
}
我的问题是,当文件上传失败时,它仍然显示预览图像,所以我需要在这些文件上传失败时自动删除该文件,我该怎么做??
我想,如果我没理解错的话,你可以用这个代码删除图片:
Dropzone.options.dropZone = {
...
, error: function(file, message, xhr) {
$(file.previewElement).remove();
},
...
}
再读一遍文档。 此代码来自文档:
myDropzone.on("error", function(file) {
myDropzone.removeFile(file);
});
如果它适用于您的情况,请告诉我。
当连接错误为 "xhr.ontimeout" 时,函数 "error:" 不会 运行。
我需要(粘贴到 "init:" 旁边):
sending: function(file, xhr, formData) {
//Execute on case of timeout only
xhr.ontimeout = function(e) {
alert('connection interrupted');
};
}