0

使用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();
    ...
})
4

2 回答 2

1

stop事件仅在所有上传完成后触发。

$('#fileupload').bind('fileuploadstop', function (e, data) {
    location.reload();
})
于 2016-03-20T13:23:14.597 回答
0

监听fileuploadadd事件,每次事件发生时增加一些变量,这样你就知道有多少文件要上传。然后,在您的fileuploaddone事件处理程序中,增加另一个变量,以便您知道有多少已完成。当两者相等时,所有上传都已完成,因此重新加载(或您可能需要做的任何其他事情)。似乎应该有一个更好的解决方案,但是这个应该可以。

于 2012-07-21T14:03:18.297 回答