【问题标题】:DropzoneJS - create own function to upload filesDropzoneJS - 创建自己的函数来上传文件
【发布时间】:2019-06-16 17:52:31
【问题描述】:

我使用 DropzoneJS 库在我的网站上上传文件。现在,我想创建自己的函数来上传排队的文件。

我知道,我可以通过这种方式获取所有这些文件:

files = myDropzone.getQueuedFiles();

但是我现在如何创建一个 ajax 请求来发送这些文件?我需要类似file_get_contents() 函数(如在 PHP 中)来获取这些文件的内容,然后使用该参数发送 ajax 帖子。

感谢您的帮助。

【问题讨论】:

  • 您可以指定您希望在处理完所有文件后触发的网址
  • url: "class/inserir.php?funcao=teste",
  • 我的网站上有一个很长的表格,我在这个请求中发送了所有内容。在 DropzoneJS 中,我必须设置下一个 URL 来上传文件——我不想要它。我想将这些文件添加到我当前的 ajax 中并发送一个请求,但我不知道如何使用 getQueuedFiles() 函数创建这个 ajax 请求。

标签: javascript dropzone.js


【解决方案1】:

也许您可以提供更多背景信息。如果我理解正确:

function sendFile(file) {
   // Do ajax things here e.g. check out the link below
}


const files = myDropzone.getQueuedFiles(); // I'm assuming this returns an array?
files.forEach(sendFile) // For each loops over the array, and calls the sendFile function with as first parameter the current item in the array, which is in your case one of your files

使用 vanilla javascript 发出 AJAX 请求: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest

【讨论】:

猜你喜欢
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多