2017-06-20 48 views
1

我有一个悬浮窗的设置与下面的脚本:悬浮窗发送空

<script> 
    Dropzone.options.myDropzone = { 
     url: 'assets/PHP/createNieuws.php', 
     autoProcessQueue: false, 
     uploadMultiple: true, 
     parallelUploads: 1, 
     maxFiles: 1, 
     maxFilesize: 1, 
     acceptedFiles: 'image/*', 
     addRemoveLinks: true, 
     createImageThumbnails: true, 
     init: function() { 
      dzClosure = this; // Makes sure that 'this' is understood inside the functions below. 

      this.on("success", function (file, responseText) { 
       console.log(responseText); 
      }); 

      // for Dropzone to process the queue (instead of default form behavior): 
      document.getElementById("submit").addEventListener("click", function (e) { 
       // Make sure that the form isn't actually being sent. 
       e.preventDefault(); 
       e.stopPropagation(); 
       if (dzClosure.getQueuedFiles().length > 0) { 
        dzClosure.processQueue(); 
       } else { 
        dzClosure.uploadFiles([{ name: 'nofiles' }]); //send empty 
       } 
      }); 

      //send all the form data along with the files: 
      this.on("sendingmultiple", function (data, xhr, formData) { 
       formData.append("titel", jQuery("#titel").val()); 
       formData.append("artikel", jQuery("#artikel").val()); 
      }); 
     } 
    } 
</script> 

,我也有一个名为为Default.png我的服务器上的文件。如果没有检测到图像,我希望dropzone引用default.png。正如你可以看到我已经tryed该解决方案已经没有更迭:https://stackoverflow.com/a/41044001/6396380

这将返回下面的错误在我的铬控制台:

dropzone.js:1497遗漏的类型错误:无法读取的未定义的属性“文件名”

我的dropzone版本是5.1.0。

任何想法如何解决这个问题?

回答

2

发生这种情况是因为新版本假定有file.upload对象与filename。改变你的模拟文件到

{ name: 'nofiles', upload: { filename: 'nofiles' } } 

应该做的伎俩。

您还应升级到5.1.1,因为它解决了与此相关的错误。

+0

它工作正常,在Chrome但Firefox给了一个错误:'类型错误:FormData.append的参数2未实现接口Blob.'我米使用版本5.1.1 – leoel

+0

嗨:D你知道这个答案吗? https://stackoverflow.com/questions/45264550/how-to-upload-a-smaller-version-and-the-original-image-in-dropzone-js – TheProgrammer

0

对于同时使用uploadFiles功能,但仍希望获得与您处理一切提交的柏XHR请求并适当追加方法在Firefox错误的人,我建议,而不是使用

dropzone.uploadFile({ name: 'nofiles', upload: { filename: 'nofiles' } })

使用

dropzone._uploadData([{ upload: { filename: '' } }], [{ filename: '', name: '', data: new Blob() }]);