Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8142601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:52:06+00:00 2026-06-06T12:52:06+00:00

I would like to use XHR object’s progress event to get the progress of

  • 0

I would like to use XHR object’s “progress” event to get the progress of download.

Here’s example code from MDN

var req = new XMLHttpRequest();

req.addEventListener("progress", updateProgress, false);
req.addEventListener("load", transferComplete, false);
req.addEventListener("error", transferFailed, false);
req.addEventListener("abort", transferCanceled, false);

req.open();

...

// progress on transfers from the server to the client (downloads)
function updateProgress(evt) {
  if (evt.lengthComputable) {
    var percentComplete = evt.loaded / evt.total;
    ...
  } else {
    // Unable to compute progress information since the total size is unknown
  }
}

function transferComplete(evt) {
  alert("The transfer is complete.");
}

function transferFailed(evt) {
  alert("An error occurred while transferring the file.");
}

function transferCanceled(evt) {
  alert("The transfer has been canceled by the user.");
}

I’ve written similar code, but lengthComputable field of the progress event turns out to be false. The loaded field is some finite value, but total is set to zero.

From the comment in the code example above, I can see that the browser doesn’t get enough information in the HTTP response to calculate a meaningful download progress.

What is the correct way to write the response to make this work? The response I see in my testing has Transfer-encoding: chunked and Content-Length: 8. I am generating it from Tornado Web server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:52:09+00:00Added an answer on June 6, 2026 at 12:52 pm

    In the chunked transfer encoding, the total length of the response is not indicated by the server, and therefore not known to the client in advance.

    You can try two things.

    • Either disable chunked transfer encoding in favor of the normal approach with Content-Length. This is what the Progress Events specification requires. But I don’t know if/how this is possible with Tornado.
    • Or, include total length in a custom response header like X-Total-Length. Then, use code like this to determine your percentage:

      function updateProgress(evt) {
        var total = evt.lengthComputable ?
                    evt.total : parseInt(req.getResponseHeader('X-Total-Length'));
        if (total) {
          var percentComplete = evt.loaded / total;
          // ...
        }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like use unmanaged code from C in C#. I built a DLL
I would like to use widgets from jQuery Mobile - buttons, drop down list,
I would like test code in the lib directory of Rails. I use RubyTest
Would like to use the return of: http://maps.google.de/maps/suggest?q=ham&cp=1&hl=de&gl=de&v=2&json=b as a JSON object in a
I would like use from Spring.NET Aspect library Logging aspect together with log4Net. I
i would like use a variable session ($_session) but it doesn't work in Drupal
I would like to use the Eigen matrix library as the linear algebra engine
I would like to use DocumentFragment and querySelector to make and modify DocumentFragments. I
I would like to use swf animations in my application. 1. Is it possible
I would like to use a grid view that can expand its rows, also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.