Autor | Zpráva | ||
---|---|---|---|
holi Profil |
#1 · Zasláno: 21. 11. 2012, 14:48:30
Zdravím,
mám níže uvedený kod pro multi upload souboru. A chci se zeptat, jak spustit upload postupně, neboli chci aby "for" počkal než se provede první upload souboru a pak až začal další. Druhá možnost je nechat to tak jak to je i když se upload dalších souborů spustí skoro stejně jako ten první, ale jak je od sebe rozpoznat abych mohl měnit progress bary ? $(document).delegate(':file', 'change', function(event){ var query = confirm('Chcete nahrát tento soubor ?'); if(query == false){ return false; } var count = event.target.files.length; countFor = count - 1; $('body').append('<div class="uploadingFiles"><table></table></div>'); for(var i = 0; countFor >= i; i++){ $('.uploadingFiles table').append('<tr rel="' + i + '-uplodingFileInfo"><td>' + event.target.files[i].name + '</td><td>0/' + event.target.files[i].size + '</td><tr rel="' + i + '-uploadingFileProgress"><td colspan="2"><progress min="0" max="100" value="0">0%</progress></td></tr><tr rel="' + i + '-uploadingFileOther" style="margin-bottom: 10px;"><td colspan="2"></td></tr>'); } for(file = 0; countFor >= file; file++){ //console.dir(file); var formData = event.target.files[file]; $.ajax({ url: $(':file').attr('rel'), //server script to process data type: 'POST', xhr: function() { // custom xhr myXhr = $.ajaxSettings.xhr(); if(myXhr.upload){ // check if upload property exists myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload } return myXhr; }, //Ajax events //beforeSend: beforeSendHandler(event.target.files), //success: completeHandler, //error: errorHandler, // Form data data: formData, //Options to tell JQuery not to process data or worry about content-type cache: false, contentType: false, processData: false }); } }); function progressHandlingFunction(e){ if(e.lengthComputable){ var percent = (Math.round(((e.loaded / e.total) * 1000 )) / 10); $('tr[rel="' + file + '-uploadingFileProgress"] progress').attr({value: percent}).text(percent + "%"); $('tr[rel="' + file + '-uploadingFileInfo"] :last-child').text(e.loaded + " / " + e.total); console.dir("Bylo nahráno " + e.loaded + " z " + e.total + " -> " + percent + "%"); console.dir(myXhr); } } Předem děkuji za pomoc a názory. |
||
Časová prodleva: 11 let
|
0