jQuery dropzone,js上传后如何刷新页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18765183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I refresh the page after dropzone,js upload?
提问by user1828871
I'm using dropzone.js to enable drag and drop to my fileupload.
我正在使用 dropzone.js 来启用拖放到我的文件上传。
I've set autoProcessQueues to false, and I'm running the processQueue command on all files added to the upload container.
我已将 autoProcessQueues 设置为 false,并且正在对添加到上传容器的所有文件运行 processQueue 命令。
Is there any way to refresh the page after all of the files has been processed? I cant se any callback function in the processQueue function..
处理完所有文件后,有没有办法刷新页面?我无法在 processQueue 函数中设置任何回调函数..
回答by Josh
Here is a complete solution combining the other contributors solutions where dropzoneJsForm
is the id
of your dropzone form. This script runs on page load and initialises the dropzone with these options. (I did not disable autodiscover).
这里是一个完整的解决方案相结合的其他贡献者解决方案,其中dropzoneJsForm
是id
您的悬浮窗的形式。此脚本在页面加载时运行并使用这些选项初始化放置区。(我没有禁用自动发现)。
// Initialise DropZone form control
// dropzoneJsForm = the id of your dropzone form
Dropzone.options.dropzoneJsForm = {
maxFilesize: 10, // Mb
init: function () {
// Set up any event handlers
this.on('completemultiple', function () {
location.reload();
});
}
};
Edit: There is now a completemultiple
event so you don't need to check the queue lengths.
编辑:现在有一个completemultiple
事件,因此您无需检查队列长度。
回答by Zafar
There is no need for you to check manually if all the files have been uploaded. There is a default function provided by Dropzone, and it fires once all the files have been processed in the queue. Use queuecomplete
to your advantage.
如果所有文件都已上传,则无需手动检查。Dropzone 提供了一个默认函数,一旦队列中的所有文件都被处理,它就会触发。使用queuecomplete
你的优势。
use this:
用这个:
this.on("queuecomplete", function (file) {
location.reload();
});
回答by A.J.
Here is what you need to do exactly.
这就是您需要做的事情。
Init your plugin.
初始化你的插件。
Dropzone.autoDiscover = false;
this line is used to turn off auto discovery of dropzone.
此行用于关闭 dropzone 的自动发现。
var md = new Dropzone(".mydropzone", {
url: "/user/upload/", # your post url
maxFilesize: "5", #max file size for upload, 5MB
addRemoveLinks: true # Add file remove button.
});
Bind Complete method
绑定完成方法
md.on("complete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
alert('Your action, Refresh your page here. ');
}
md.removeFile(file); # remove file from the zone.
});
I hope this helps.
我希望这有帮助。
回答by Gandarez
Try handling the event 'complete'.
尝试处理事件“完成”。
$dropzone.on('complete', function () {
location.reload();
});
回答by DanJGer
I would use completeMultiple
handler but you have to properly handle the uploads as an array of file[]
or files[]
. If you really don't want to deal with that then either set maxFiles: 1
or check the queue to be sure nothing else is uploading so that the page refresh cancels anything pending. You can check the queue using:
我会使用completeMultiple
处理程序,但您必须正确处理作为file[]
or数组的上传files[]
。如果您真的不想处理这个问题,那么设置maxFiles: 1
或检查队列以确保没有其他内容正在上传,以便页面刷新取消任何挂起的内容。您可以使用以下方法检查队列:
if (myDropzone.getQueuedFiles().length == 0 && myDropzone.getUploadingFiles().length == 0)