简体   繁体   English

如何等待多个jquery文件上传?

[英]How do I wait for multiple jquery file uploads?

I'm trying to refresh the page after multiple files have been uploaded using jquery file upload : 我正在尝试使用jquery文件上传功能上传多个文件后刷新页面:

For some reason my test message is being called after each individual file upload completion and I'm trying to call this just once after all the files have uploaded. 由于某种原因,在每个文件上载完成后都会调用我的测试消息,而我试图在所有文件上载后仅调用一次。 Is this possible? 这可能吗?

HTML: HTML:

<form id="fileupload" action="server/php/" method="POST" enctype="multipart/form-data">
    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
    <div class="row fileupload-buttonbar">
        <div class="span7">
            <!-- The fileinput-button span is used to style the file input field as button -->
            <span class="btn btn-success fileinput-button">
                <i class="icon-plus icon-white"></i>
                <span>Add files...</span>
                <input type="file" name="files[]" multiple>
            </span>
            <button type="submit" class="btn btn-primary start">
                <i class="icon-upload icon-white"></i>
                <span>Start upload</span>
            </button>
        </div>
    </div>
    <!-- The loading indicator is shown during file processing -->
    <div class="fileupload-loading"></div>
    <br>
    <!-- The table listing the files available for upload/download -->
    <table role="presentation" class="table table-striped"><tbody class="files" data-toggle="modal-gallery" data-target="#modal-gallery"></tbody></table>
</form>

JQuery jQuery查询

$('#fileupload').bind('fileuploadcompleted', function (e, data) {
    e.preventDefault();

    // I would expect to see this after all files ahve uplaoded but I see it for each file upload ?
    alert("Completed");

    //location.reload();
    ...
})

Listen for the fileuploadadd event, and each time it occurrs increment some variable so you know how many files there are to upload. 监听fileuploadadd事件,每次它发生时,它都会增加一个变量,以便您知道有多少个文件要上传。 Then, in your fileuploaddone event handler, increment another variable so you know how many have finished. 然后,在您的fileuploaddone事件处理程序中,递增另一个变量,以便您知道有多少个变量已完成。 When the two are equal, all uploads are done, so do your reload (or whatever else you may need to do). 当两者相等时,所有上传均已完成,请重新加载(或可能需要执行的其他任何操作)。 It seems there should be a better solution, but this one should work. 似乎应该有一个更好的解决方案,但是这个解决方案应该可以工作。

stop event is only triggered after all uploads are finished. 仅在所有上传完成后才触发stop事件。

$('#fileupload').bind('fileuploadstop', function (e, data) {
    location.reload();
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM