javascript - 无法读取空 dropzone 的属性 'removeChild'

标签 javascript jquery dropzone.js

我有这个代码:

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/

相关文章:

javascript - 如何在整页图像 slider 中提供箭头键事件

javascript - Angular js - ngDialog 如何从 Controller 打开对话框?

javascript - 如何计算 Google Maps Javascript API 中多个多边形的中心?

javascript - 如何使用 onstart 和 oncomplete 创建 jquery 函数

jquery - .is (':checked' ) 始终返回 true

c# - razor 页面上的 Dropzone 返回 400 状态代码

javascript - 无法解析模块 "events"React-Native

javascript - JQuery 的 .click() 在幕后是如何工作的?

javascript - dropzone - var this 在第一次单击时在另一个函数的回调中不起作用(xhr formdata)

c# - 通过 Dropzone.js 将某些文件类型上传到服务器