我有这个代码:
JS代码:
var currentFile = null;
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#myDrop", {
url : "<?php echo $this->serverUrl() . '/profile/ajax/dzupload'; ?>",
paramName : 'profilepicture',
acceptedFiles : "image/*",
maxFiles : 1,
addRemoveLinks : true,
init : function() {
var fileName = $('#profilePicture').val();
var mockFile = { name: fileName, size: 12345 };
this.options.addedfile.call(this, mockFile);
this.options.thumbnail.call(this, mockFile, "<?php echo $this->serverUrl().'/public/profile/'.'usr'.$practitionerInfo->user_id.'/picture/'.$practitionerInfo->profilepicture ?>");
currentFile = mockFile;
this.on("addedfile", function(file) {
if (currentFile) {
this.removeFile(currentFile);
}
currentFile = file;
});
this.on("success", function(file, responseText) {
$('#profilePicture').attr("value", responseText.filename);
console.log(responseText );
});
this.on("maxfilesexceeded", function(file){
this.removeFile(file);
alert("You are not allowed to chose more than 1 file!");
});
this.on("removedfile", function (file){
$.ajax({
method: 'POST',
url: '<?php echo $this->serverUrl() . '/profile/ajax/dzdelete' ?>',
data: {
area : 'company-profile',
name : $('#profilePicture').attr('value')
},
success: function(result){
$('#profilePicture').attr("value", '')
console.log(result);
}
})
});
}
});
错误:
Cannot read property 'removeChild' of null
什么原因导致此错误? 怎么解决呢?
使用上传功能时出现此错误
从来没有遇到过有人出现这样的错误?我该如何改进我的代码,使其只出现这个错误?
提前致谢!
最佳答案
将removedfile方法替换为这样
if ((_ref = file.previewElement) != null) {
//_ref.parentNode.removeChild(file.previewElement);
_ref.style.display = "none";
}
在文件 dropzone.js
关于javascript - 无法读取空 dropzone 的属性 'removeChild',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35985840/