Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to correctly write http response so as to use XHR progress event listener
    primarykey
    data
    text
    <p>I would like to use XHR object's "progress" event to get the progress of download. </p> <p>Here's example code from <a href="https://developer.mozilla.org/en/using_xmlhttprequest#Monitoring_progress" rel="nofollow">MDN</a></p> <pre><code>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."); } </code></pre> <p>I've written similar code, but <code>lengthComputable</code> field of the progress event turns out to be false. The <code>loaded</code> field is some finite value, but <code>total</code> is set to zero.</p> <p>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.</p> <p>What is the correct way to write the response to make this work? The response I see in my testing has <code>Transfer-encoding: chunked</code> and <code>Content-Length: 8</code>. I am generating it from Tornado Web server.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload