dropzone.js表单提交不发送文件 [英] dropzone.js form submit not sending file

查看:152
本文介绍了dropzone.js表单提交不发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用标准html表单中的Dropzone.js时遇到了一些麻烦。使用我的代码,一切正常,我可以单击该区域添加图像,我一次只能添加一个图像,并且只有在按下提交按钮时才会上传图像。
但是,按下提交时实际上没有发送任何内容。我知道我需要手动处理队列,但这似乎根本不起作用。然而,其余的表单数据被发送,它只是不是的图像。

I'm having some trouble with using Dropzone.js within a standard html form. 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

<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 !!!在我之前链接的github帖子的作者的帮助下,这个问题现在已经解决了!

Bingo!!! With some help from the author of the github post i linked to earlier, this issue has now been resolved!

我之前发布的代码按原样运行,但是在dropzone.js文件,我添加了这两行 this.hiddenFileInput.setAttribute(name,_ this.options.paramName);
$(form.dropzone)。append(_this.hiddenFileInput);

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);

文件之后.body.appendChild(_this.hiddenFileInput); 并且一切正常!

这篇关于dropzone.js表单提交不发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆