简体   繁体   English

dropzone.js表单提交未发送文件

[英]dropzone.js form submit not sending file

I'm having some trouble with using Dropzone.js within a standard html form. 我在标准html表单中使用Dropzone.js遇到麻烦。 With the code I have, everything is working as it should, I can click the area to add an image, I can only add one image at a time, and the image is only uploaded when the submit button is pressed. 使用我拥有的代码,一切都可以正常工作,我可以单击该区域以添加图像,一次只能添加一个图像,并且仅在按下提交按钮时才能上传图像。 However, nothing is actually sent when submit is pressed. 但是,按下提交时实际上什么也没有发送。 I know I need to manually process the queue, but this doesn't seem to be working at all. 我知道我需要手动处理队列,但这似乎根本不起作用。 The rest of the form data is sent however, it's only the image which isn't. 表单数据的其余部分将发送,但是只有图像没有发送。

I'm using the following simplified code. 我正在使用以下简化代码。 (Assume that this works other than no file being sent.) (假设除了不发送文件外,其他方法都可以。)

HTML 的HTML

<form action='upload.php' method="post" class="dropzone" id="mydz">
<input type='submit' name='submitimage' value='Save' style='float:left;'/>

JAVASCRIPT JAVASCRIPT

Dropzone.options.mydz = {
   autoProcessQueue: false,
   maxFiles: 1,

   init: function() {
      var submitButton = document.querySelector("#submitimage");
      mydz = this; // closure

      submitButton.addEventListener("click", function() {
         mydz.processQueue(); // Tell Dropzone to process all queued files.
      });                                    

      this.on('addedfile', function(file){ if(this.files.length > 1) { this.removeFile(this.files[0]); } });
   }
}

I've been trying to solve this all day now, and no amount of searching online has revealed anything useful to me. 我一直在努力解决这一问题,而且在线搜索没有发现对我有用的东西。 Can any of you help?? 你们任何人可以帮忙吗? :) :)

Bingo!!! 答对了!!! With some help from the author of the github post i linked to earlier, this issue has now been resolved! 在我之前链接到的github帖子的作者的帮助下,此问题现已解决!

The code I posted earlier works as it is, however inside the dropzone.js file, I added these two lines this.hiddenFileInput.setAttribute("name", _this.options.paramName); $("form.dropzone").append(_this.hiddenFileInput); 我之前发布的代码按原样工作,但是在dropzone.js文件中,我在这两行中添加了这行this.hiddenFileInput.setAttribute("name", _this.options.paramName); $("form.dropzone").append(_this.hiddenFileInput); this.hiddenFileInput.setAttribute("name", _this.options.paramName); $("form.dropzone").append(_this.hiddenFileInput);

after document.body.appendChild(_this.hiddenFileInput); document.body.appendChild(_this.hiddenFileInput); and all is working as it should! 一切都按预期进行!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM