javascript - DropzoneJS - 创建自己的函数来上传文件
问题描述
我使用 DropzoneJS 库在我的网站上上传文件。现在,我想创建自己的函数来上传排队的文件。
我知道,我可以通过这种方式获取所有这些文件:
files = myDropzone.getQueuedFiles();
但是我现在如何创建一个 ajax 请求来发送这些文件呢?我需要类似file_get_contents()
函数(如在 PHP 中)来获取这些文件的内容,然后使用该参数发送 ajax 帖子。
谢谢你的帮助。
解决方案
也许您可以提供更多背景信息。如果我理解正确:
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
推荐阅读
- java - 适当调整图像大小
- php - Laravel 管理员本地化
- electron - Electron Windows 安装程序未在桌面上创建快捷方式
- c++ - 在多线程环境中正确销毁对象
- web-config - 如果我将现有的 Web 应用程序部署到 Azure,有没有办法自动映射现有的 web.config 设置?
- python - Django Model.objects.create() DB 异常没有过滤
- c# - Powershell 忽略通过 SessionStateProxy.SetVariable 传递的参数
- opencv - 如何从纸(opencv)中提取这6个符号(签名)
- php - PHP - 从 MySQL DB 中填充选择下拉列表,并在表单中自动填充该字段
- android - 更改 MaterialButton 的 BackgroundTint