jQuery recursive function to upload many files while giving the user some feedback

Posted by checcco on Stack Overflow See other posts from Stack Overflow or by checcco
Published on 2010-04-15T10:10:44Z Indexed on 2010/04/15 10:13 UTC
Read the original article Hit count: 184

Filed under:
|
|
|

Hi guys, I'm trying to write a jQuery function to let users upload many files at once. Here's the function I thought to give the user some feedback about the upload process progress.

function uploadFiles(numbersOfFiles, start) {
   $("#info").html(start + " files uploaded");
   $.post('upload.php', {
      start: start
   }, function (data) {
      start += 5;
      if (start < numbersOfFiles) {
         $("#info").html(start + " files uploaded");
         uploadFiles(numbersOfFiles, start);
      } else {
         $("#info").html("All files have been uploaded");
      }
   });
}

The function calls a php script to upload 5 files, then if there are more files to upload it calls the script again. The whole process works. I've tried it with 100 files. The only thing that doesn't work is the #info div updating. The div get updated the first time and then again only to show "All files have been uploaded". So there's no feedback for the user about the uploading process. I can't understand why... Any help?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about php