javascript - 使用 laravel 5.7 实现 dropzone 时出错
问题描述
我在使用 laravel 5.7 将 DROPZONE 与系统上的表单文本集成时遇到问题。
我阅读了文档,但无法实现。参考:https ://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone
我阅读了一些教程,例如: https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone https://jsfiddle.net/gued9y6m/ ...但没有一个符合我的标准
js文件
Dropzone.options.myAwesomeDropzone = { // The camelized version of the ID of the form element
// The configuration we've talked about above
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
maxFiles: 100,
// The setting up of the dropzone
init: function() {
var myDropzone = this;
// First change the button to actually tell Dropzone to process the queue.
this.element.querySelector("button[type=submit]").addEventListener("click", function(e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
// Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
// of the sending event because uploadMultiple is set to true.
this.on("sendingmultiple", function() {
// Gets triggered when the form is actually being sent.
// Hide the success button or the complete form.
});
this.on("successmultiple", function(files, response) {
// Gets triggered when the files have successfully been sent.
// Redirect user or notify of success.
});
this.on("errormultiple", function(files, response) {
// Gets triggered when there was an error sending the files.
// Maybe show form again, and notify user of error
});
}
}
形式(blade.php)
<form id="my-awesome-dropzone" class="dropzone">
<div class="dropzone-previews"></div> <!-- this is were the previews
should be shown. -->
<!-- Now setup your input fields -->
<input type="email" name="username" />
<input type="password" name="password" />
<button type="submit">Submit data and files!</button>
</form>
我想要什么:用户必须填写所有表单字段,添加照片,当我单击“全部发送”时,ajax 请求将所有字段(包括照片)发送到我的控制器中的一个方法,它将是存储在数据库中。
解决方案
推荐阅读
- java - 简单的 XML 注释问题
- java - 在 spring kafka consumer 1.2.x 中寻求方法行为
- javascript - 在同一个控制器中处理不同的 routeParams
- java - Groovy Spring Contract DLS 将字符串转换为 JSON
- ipv6 - 如果我想在一个文件中存储 2^128 个 IPv6 地址,那么所有地址的文件大小是多少?
- sql-server - 连接子行同时尊重 Where 子句与或
- bash - UNIX:这些 ====== 有什么用?
- css - CSS 媒体查询未检测到视口宽度的变化
- c# - 当我们开始使用 Accord 捕获视频时,CPU 和内存消耗会很高
- java - Servlet 应用程序 - tomcat \log 文件夹中的自定义日志文件名