【发布时间】:2017-01-04 00:16:52
【问题描述】:
我有以下表格:
<form class="block-center" id="pdfForm" method="POST" action="form_threatment.php" enctype="multipart/form-data" style="margin-top: 30px;">
<div class="form-group push-50-t col-md-12">
<div class="col-md-12">
<div class="form-material form-material-primary">
<div class="dropzone dropzone-previews" id="pdfFile">
</div>
</div>
</div>
</div>
</div>
<div class="form-group push-50-t col-md-6">
<div class="col-md-12">
<div class="form-material form-material-primary">
<input class="form-control" name="first_name" type="text" id="first_name" />
<label for="first_name"><span class="asterix">*</span> Prénom : </label>
</div>
</div>
</div>
我包含这样的 dropzone.js 库:
<script src="assets/js/dropzone.js"></script>
还有我自己的 dropzone myDropzone.js :
<script src="assets/js/myDropzone.js"></script>
在myDropzone.js 文件中,我以这种方式配置了 div#pdfFile:
Dropzone.autoDiscover = false;
$(document).ready(function() {
Dropzone.options.pdfFile = {
// url does not has to be written if we have wrote action in the form tag but i have mentioned here just for convenience sake
url: 'form_threatment.php',
acceptedFiles: '.pdf',
maxFilesize: 20,
addRemoveLinks: true,
autoProcessQueue: false, // this is important as you dont want form to be submitted unless you have clicked the submit button
uploadMultiple: false,
autoDiscover: false,
paramName: 'pdf', // this is optional Like this one will get accessed in php by writing $_FILE['pic'] // if you dont specify it then by default it taked 'file' as paramName eg: $_FILE['file']
previewsContainer: '#pdfFile', // we specify on which div id we must show the files
clickable: false, // this tells that the dropzone will not be clickable . we have to do it because v dont want the whole form to be clickable
accept: function(file, done) {
console.log("uploaded");
done();
},
error: function(file, msg){
alert(msg);
},
init: function() {
var myDropzone = this;
// #submit-all it the id of the submit button
$("#submit-all").on("click", function(e) {
var files = $('#pdfFile').get(0).dropzone.getAcceptedFiles();
console.log(myDropzone);
console.log(files);
//e.preventDefault();
//e.stopPropagation();
myDropzone.processQueue(); // this will submit your form to the specified action path
// after this, your whole form will get submitted with all the inputs + your files and the php code will remain as usual
//REMEMBER you DON'T have to call ajax or anything by yourself, dropzone will take care of that
});
}
};
Dropzone.options.pdfFile.init();
});
加载页面时出现错误:
未捕获的错误:未提供 URL。
之前,我修改了 dropzone.js 文件来设置 Dropzone 选项,但我重置了 dropzone.js 库文件并决定在 myDropzone.js 中设置选项强>文件。
在 dropzone.js 文件中设置选项时,我没有错误,但在我重置这些选项并在 myDropzone.js 中设置它们之后,我有这个错误让我相信 myDropzone.js 中的选项未初始化。
事实上,当我点击 #submit-all 按钮时,init() 函数可以正常工作。
请问有什么办法解决这个问题吗?
好的,我解决了:
未捕获的错误:未提供 URL。
删除它。
现在,当我提交时,我收到以下错误:
未捕获的类型错误:myDropzone.processQueue 不是函数
在 init() 函数中。
编辑:
我解决了上一个错误,删除了 processQueue 函数,并阻止了我上传页面的 Validate 按钮,直到 PDF 没有成功上传。 我知道这是一个丑陋的 hack,但我没有找到其他方法。
【问题讨论】:
-
Uncaught Error: No URL provided- 任何指示此错误在哪一行代码上? -
它在 dropzone.js 的第 440 行引发,即:
if (!this.options.url) { throw new Error("No URL provided."); }这是在 dropzone.js 库的函数function Dropzone(element, options)中。我应该在 dropzone.js 之前导入 myDropzone.js 吗? -
绝对不要颠倒这两个文件的顺序 - 你当然没有设置任何
options.url所以你得到这个错误是有道理的 -
我在 myDropzone.js 中提供了 url:
url: 'form_threatment.php',+ 表单操作也是form_threatment.php。 -
不,那是
options.pdfFile.url
标签: javascript jquery dropzone.js