How to calculate the download site? I saw on the sites the status of loading the site, I know that XMLHttpRequest has an upload.onprogress event for uploading to the server :

XMLHttpRequest.upload.onprogress = function(event) { console.log( 'Загружено на сервер ' + event.loaded + ' байт из ' + event.total ); } 

How to do the same, but to download (download) page / data from the server ?

    1 answer 1

     var oReq = new XMLHttpRequest(); oReq.addEventListener("progress", updateProgress); oReq.addEventListener("load", transferComplete); oReq.addEventListener("error", transferFailed); oReq.addEventListener("abort", transferCanceled); oReq.open(); // ... // progress on transfers from the server to the client (downloads) function updateProgress (oEvent) { if (oEvent.lengthComputable) { var percentComplete = oEvent.loaded / oEvent.total; // ... } else { // Unable to compute progress information since the total size is unknown } } function transferComplete(evt) { console.log("The transfer is complete."); } function transferFailed(evt) { console.log("An error occurred while transferring the file."); } function transferCanceled(evt) { console.log("The transfer has been canceled by the user."); } 

    http://jsfiddle.net/GvdSy/

    Jquery:

     $.ajax({ type: 'POST', url: "/", data: {}, beforeSend: function(XMLHttpRequest) { // прогресс загрузки на сервер XMLHttpRequest.upload.addEventListener("progress", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; // делать что-то... } }, false); // прогресс скачивания с сервера XMLHttpRequest.addEventListener("progress", function(evt){ if (evt.lengthComputable) { var percentComplete = evt.loaded / evt.total; // делать что-то... } }, false); }, success: function(data){ // делать что-то при успешном завершении... } });