gpt4 book ai didi

javascript - 完成整个过程的 jQuery FileUpload 回调

转载 作者:行者123 更新时间:2023-12-03 08:10:48 25 4
gpt4 key购买 nike

我正在使用Blueimp Jquery File Upload plugin上传文件。我想在完整的上传过程完成后做一些事情。因此,如果我(一次)拖放 4 个文件,我想在上传所有文件时调用一些代码。我怎样才能做到这一点?

我尝试过使用很多回调,例如 donestopprogressall 等,但似乎没有什么完全符合我的要求我在寻找。我需要确保在运行代码之前调用了最后一个done

我已经最接近stop,但有时似乎在done之前运行。有什么想法吗?

最佳答案

更新 - 我在评论中了解到回调触发的时间与要上传的文件数量相同。所以正确的答案是使用回调“always”并放置一个计数器。每次上传文件时计数都会增加。

// Variables to put before the .fileUpload and to be init in "add"
var nbElementsToUpload = 0;
var nbElementsUploaded = 0;


.bind('fileuploadalways', function (e, data) {
nbElementsUploaded++;
if(nbElementsToUpload === nbElementsUploaded){
/* All elements uploaded */
}
})

You are talking about the "last" done. What do you mean by that? Are you invoking 4 times the upload or one time with 4 files?

You have a list of callbacks functions for the plugin. https://github.com/blueimp/jQuery-File-Upload/wiki/Options#callback-options

If you want to capture successful upload requests, then use "done" https://github.com/blueimp/jQuery-File-Upload/wiki/Options#done

If you want to capture all completed operations once done (including errors and abort), then use the callback "always". https://github.com/blueimp/jQuery-File-Upload/wiki/Options#always

I'm myself using this plugin without issues with "done" and "fail". Example:

}).on('fileuploaddone', function (e, data) { // code here })
.on('fileuploadfail', function (e, data) { // code here })

You can add console.log to correctly see what happends and in which order.

Regards,

关于javascript - 完成整个过程的 jQuery FileUpload 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34156421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com