最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Refreshing the page after completing uploads in jQuery Multi file Uploader - Stack Overflow

programmeradmin7浏览0评论

I'm using jQuery Multifile uploader () with PHP

and I want to refresh the uploads page once all files got uploaded, I'm using basic plus UI, please tell me if is there any easy way to achieve it

I'm using jQuery Multifile uploader (https://github./blueimp/jQuery-File-Upload) with PHP

and I want to refresh the uploads page once all files got uploaded, I'm using basic plus UI, please tell me if is there any easy way to achieve it

Share Improve this question edited Jun 21, 2018 at 1:10 Cœur 38.7k26 gold badges202 silver badges277 bronze badges asked Sep 5, 2013 at 12:50 Peterson AndrewPeterson Andrew 2436 silver badges16 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 11

Use the done and fail events along with some counters. Found these events in the options documentation.

var fileCount = 0, fails = 0, successes = 0;

$('#fileupload').fileupload({
    url: 'server/php/'
}).bind('fileuploaddone', function(e, data) {
  fileCount++;
  successes++;
  console.log('fileuploaddone');
  if (fileCount === data.getNumberOfFiles()) {
    console.log('all done, successes: ' + successes + ', fails: ' + fails);
    // refresh page
    location.reload();
  }
}).bind('fileuploadfail', function(e, data) {
  fileCount++;
  fails++;
  console.log('fileuploadfail');
  if (fileCount === data.getNumberOfFiles()) {
    console.log('all done, successes: ' + successes + ', fails: ' + fails);
    // refresh page
    location.reload();
  }
});

You can use the stop event. It is equivalent to the global ajaxStop event (but for file upload requests only).

stop: function(e){
      location.reload();
}

I have used this code and so far it works well.

$('#fileupload').bind('fileuploadstop', function (e) {
  console.log('Uploads finished');        
    location.reload(); // refresh page
    });

I used ryan's code, but there was a problem. The value of data.getNumberOfFiles() was decreasing as the files were uploaded while fileCount was increasing, so my upload script got interrupted at the middle of my upload where data.getNumberOfFiles() was equal to fileCount.

Here is how i tweaked ryan's script and now it's working like a charm:

var fileCount = 0, fails = 0, successes = 0;
var _totalCountOfFilesToUpload = -1;

$('#fileupload').bind('fileuploaddone', function (e, data) {
    if (_totalCountOfFilesToUpload < 0) {
         _totalCountOfFilesToUpload = data.getNumberOfFiles();
    }
    fileCount++;
    successes++;
    if (fileCount === _totalCountOfFilesToUpload) {
        console.log('all done, successes: ' + successes + ', fails: ' + fails);
        // refresh page
        location.reload();
    }
}).bind('fileuploadfail', function(e, data) {
    fileCount++;
    fails++;
    if (fileCount === _totalCountOfFilesToUpload) {
        console.log('all done, successes: ' + successes + ', fails: ' + fails);
        // refresh page
        //location.reload();
    }
});

I hope this will help other people as well as! :)

发布评论

评论列表(0)

  1. 暂无评论