无法读取空放置区的属性“删除子项”

Cannot read property 'removeChild' of null dropzone

本文关键字:删除 删除子项 属性 读取 置区      更新时间:2023-09-26

我有这个代码:

代码 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";
}

在文件拖放区中.js