2016-03-14 2 views
0

У меня есть этот код:Не удается прочитать свойство 'RemoveChild' нулевого DropZone

КОД 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 

Что вызывает эту ошибку? Как я могу это решить?

Эта ошибка возникает, когда я получаю от функции Upload

Он никогда не встречал никого с такой ошибкой? Как я могу улучшить свой код так, чтобы она была только эта ошибка?

Заранее благодарен!

ответ

1

Заменить removedfile метод, чтобы быть как этот

if ((_ref = file.previewElement) != null) { 
    //_ref.parentNode.removeChild(file.previewElement); 
    _ref.style.display = "none"; 
} 

в файле dropzone.js

Смежные вопросы