[英]How do I wait for multiple jquery file uploads?
我正在嘗試使用jquery文件上傳功能上傳多個文件后刷新頁面:
由於某種原因,在每個文件上載完成后都會調用我的測試消息,而我試圖在所有文件上載后僅調用一次。 這可能嗎?
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查詢
$('#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();
...
})
監聽fileuploadadd
事件,每次它發生時,它都會增加一個變量,以便您知道有多少個文件要上傳。 然后,在您的fileuploaddone
事件處理程序中,遞增另一個變量,以便您知道有多少個變量已完成。 當兩者相等時,所有上傳均已完成,請重新加載(或可能需要執行的其他任何操作)。 似乎應該有一個更好的解決方案,但是這個解決方案應該可以工作。
僅在所有上傳完成后才觸發stop
事件。
$('#fileupload').bind('fileuploadstop', function (e, data) {
location.reload();
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.