我有一个带有以下脚本的拖放区设置:
<script>
Dropzone.options.myDropzone = {
url: 'assets/PHP/createNieuws.php',
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 1,
maxFiles: 1,
maxFilesize: 1,
acceptedFiles: 'image/*',
addRemoveLinks: true,
createImageThumbnails: true,
init: function () {
dzClosure = this; // Makes sure that 'this' is understood inside the functions below.
this.on("success", function (file, responseText) {
console.log(responseText);
});
// for Dropzone to process the queue (instead of default form behavior):
document.getElementById("submit").addEventListener("click", function (e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
if (dzClosure.getQueuedFiles().length > 0) {
dzClosure.processQueue();
} else {
dzClosure.uploadFiles([{ name: 'nofiles' }]); //send empty
}
});
//send all the form data along with the files:
this.on("sendingmultiple", function (data, xhr, formData) {
formData.append("titel", jQuery("#titel").val());
formData.append("artikel", jQuery("#artikel").val());
});
}
}
</script>
我的服务器上还有一个名为 default.png 的文件。如果没有检测到图像,我希望 dropzone 引用 default.png 。正如你所看到的,我已经尝试过这个解决方案但没有成功:https://stackoverflow.com/a/41044001/6396380
这会在我的 Chrome 控制台中返回以下错误:
dropzone.js:1497 未捕获类型错误:无法读取未定义的属性“文件名”
我的 dropzone 版本是 5.1.0 。
有什么办法可以解决这个问题吗?
最佳答案
发生这种情况是因为新版本假设存在一个带有filename
的file.upload
对象。将您的模拟文件更改为
{ name: 'nofiles', upload: { filename: 'nofiles' } }
应该可以解决问题。
您还应该升级到 5.1.1
,因为它解决了与此相关的错误。
关于javascript - Dropzone 发送空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44656605/