469,336 Members | 5,480 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

How to check progress of XMLHTTPRequest?

Hi,

I want to asynchronously recieve large amount of data using
XMLHTTPRequest. If it is possible, I would like to make a
progress bar to show the user how the process is going.

According to the information I found, the object can only be
in five states (shown below). Is it possible to see how much
data has already been recieved when the object is in state 3?

XMLHttpRequest.readyState:

0 The object has been created, but not initialized (the open
method has not been called).
1 The object has been created, but the send method has not
been called.
2 The send method has been called, but the status and headers
are not yet available.
3 Some data has been received. Calling the responseBody and
responseText properties at this state to obtain
partial results will return an error, because status
and response headers are not fully available.
4 All the data has been received, and the complete data is
available.

If you know of some alternative way to make a progress bar for
this purpose, let me know.
Mar 30 '06 #1
10 10991

test wrote:
Hi,

I want to asynchronously recieve large amount of data using
XMLHTTPRequest. If it is possible, I would like to make a
progress bar to show the user how the process is going.

According to the information I found, the object can only be
in five states (shown below). Is it possible to see how much
data has already been recieved when the object is in state 3?

XMLHttpRequest.readyState:

0 The object has been created, but not initialized (the open
method has not been called).
1 The object has been created, but the send method has not
been called.
2 The send method has been called, but the status and headers
are not yet available.
3 Some data has been received. Calling the responseBody and
responseText properties at this state to obtain
partial results will return an error, because status
and response headers are not fully available.
4 All the data has been received, and the complete data is
available.

If you know of some alternative way to make a progress bar for
this purpose, let me know.


You could do it by only sending X data of a request at a time, then
requesting the next X segment of your total data N. Something like
this...

<part>
<bytesSent>1256</bytesSent>
<bytesTotal>102325</bytesTotal>
<data>insert whatever data you are sending here, part of the
whole</data>
</part>

Keep requesting the next part of N data, reading, updating your page,
until you have bytes total.

Mar 30 '06 #2
test wrote:
If you know of some alternative way to make a
progress bar for this purpose, let me know.


Sorry, I don't help anonymous address mungers.

<URL:http://www.interhack.net/pubs/munging-harmful/>
PointedEars
Mar 30 '06 #3
Thomas 'PointedEars' Lahn wrote:
Sorry, I don't help anonymous address mungers.
<URL:http://www.interhack.net/pubs/munging-harmful/>


Yet you waste everyone's time posting stupid responses like this?
Or ones that simply say "RTFM"?

Come on, please don't litter this group with more junk than it already has!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Mar 31 '06 #4
salute Mr. test

According to the information I found, the object can only be
in five states (shown below). Is it possible to see how much
data has already been recieved when the object is in state 3?

XMLHttpRequest.readyState:
...
3 Some data has been received. Calling the responseBody and
responseText properties at this state to obtain
partial results will return an error, because status
and response headers are not fully available.


.... and yet it is worth a try to access some of these informations.

listen to the [[XMLHttpRequest]] objects "onreadystatechange".
as long as the objects "readyState" returns its interactive status 3
try to read the objects "responseStream.length" property and as this
fails the objects "responseText.length" property as well.

when I did research in order to script just another XMLHttpRequest
interface I found "responseStream" only (no other reference states
something to "responseStream") at
[http://msdn.microsoft.com/library/en...sp?frame=true]
and I implemented it - but my test running in MSIE always switches
to the "responseText.length" fallback.

now you got the information about the objects "bytesLoaded".
you will receive the objects "totalBytes" as result of the following
header query: [[XMLHttpRequest]].getResponseHeader("Content-Length");

the rest simply is Math.

you might countercheck my test as a feasibility study at
[http://www.pseliger.de/testCases/dht...face.dev.html]
so long - peterS.

Mar 31 '06 #5
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Sorry, I don't help anonymous address mungers.
<URL:http://www.interhack.net/pubs/munging-harmful/>


Yet you waste everyone's time posting stupid responses like this?


What you call a stupid response and a waste of time, I call giving a hint,
so that OPs recognize why they do not receive help (from me) even though it
would have been possible, and therefore giving them an incentive to change
their antisocial behavior.
PointedEars
Mar 31 '06 #6
Thomas 'PointedEars' Lahn said the following on 3/31/2006 8:33 AM:
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Sorry, I don't help anonymous address mungers.
<URL:http://www.interhack.net/pubs/munging-harmful/> Yet you waste everyone's time posting stupid responses like this?


What you call a stupid response and a waste of time,


Is a stupid response and a waste of time. Call it what it is.
I call giving a hint,
99.99% of the post in this group can be answered with an RTFM. Its a
stupid, useless response. Its not a hint.

so that OPs recognize why they do not receive help (from me) even though it
would have been possible, and therefore giving them an incentive to change
their antisocial behavior.


Practice what you preach, please?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 31 '06 #7
On 31 Mar 2006 01:38:36 -0800, peterS. wrote:
salute Mr. test

According to the information I found, the object can only be
in five states (shown below). Is it possible to see how much
data has already been recieved when the object is in state 3?

XMLHttpRequest.readyState:
...
3 Some data has been received. Calling the responseBody and
responseText properties at this state to obtain
partial results will return an error, because status
and response headers are not fully available.


... and yet it is worth a try to access some of these informations.

listen to the [[XMLHttpRequest]] objects "onreadystatechange".
as long as the objects "readyState" returns its interactive status 3
try to read the objects "responseStream.length" property and as this
fails the objects "responseText.length" property as well.

when I did research in order to script just another XMLHttpRequest
interface I found "responseStream" only (no other reference states
something to "responseStream") at
[http://msdn.microsoft.com/library/en...sp?frame=true]
and I implemented it - but my test running in MSIE always switches
to the "responseText.length" fallback.

now you got the information about the objects "bytesLoaded".
you will receive the objects "totalBytes" as result of the following
header query: [[XMLHttpRequest]].getResponseHeader("Content-Length");

the rest simply is Math.

you might countercheck my test as a feasibility study at
[http://www.pseliger.de/testCases/dht...face.dev.html]
so long - peterS.


Thanks!

But I seem to have a problem: I don't recieve the
"Content-Length" header. According to Firefox's Firebug
extension, I get these headers:

GET http://localhost/mytestsite/getmessages.php?param=0
Headers:

Date: Fri, 31 Mar 2006 19:53:20 GMT
Server: Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.8
PHP/5.0.5 mod_autoindex_color
X-Powered-By: PHP/5.0.5
Keep-Alive: timeout=15, max=98
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

Is it something I have to set on the server? How?
Mar 31 '06 #8
On Fri, 31 Mar 2006 22:06:07 +0200, test wrote:

[...]
Is it something I have to set on the server? How?


OK, I've set it on the php side with:

header('Content-length: '.filesize($file));

Thanks again for your reply :)
Mar 31 '06 #9
JRS: In article <13****************@PointedEars.de>, dated Fri, 31 Mar
2006 15:33:09 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <Po*********@web.de> posted :
Matt Kruse wrote:
Thomas 'PointedEars' Lahn wrote:
Sorry, I don't help anonymous address mungers.
<URL:http://www.interhack.net/pubs/munging-harmful/>


Yet you waste everyone's time posting stupid responses like this?


What you call a stupid response and a waste of time, I call giving a hint,
so that OPs recognize why they do not receive help (from me) even though it
would have been possible, and therefore giving them an incentive to change
their antisocial behavior.

Your manner of posting is itself antisocial behaviour; follow,
therefore, your own advice. When you have nothing useful to say, then
say nothing.

You seem to consider yourself to have been elected fuehrer of this
newsgroup - you are mistaken.

While your technical ability is, although unreliable, acknowledged,
opinions on you evidently vary. Sometimes you are despised, sometimes
you are hated, but most often you seem to be considered psychologically
inadequate or mentally malformed. Even your fellow Germans over in
de.c.l.j seen to hold similar views.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Apr 1 '06 #10
Thomas 'PointedEars' Lahn wrote:
What you call a stupid response and a waste of time, I call giving a
hint, so that OPs recognize why they do not receive help (from me)
even though it would have been possible, and therefore giving them an
incentive to change their antisocial behavior.


(1) If everyone took each thread that they didn't think was worthy of a
response, and responded to tell the OP this fact, that would be extremely
stupid, no?

(2) You act as if someone should be privileged to receive a response from
you. Not so. Your responses are often less than helpful, so not getting a
response from you is hardly something someone should be concerned about.

(3) "Anti-social" describes _most_ of your posts to this group. You are
perhaps the least social regular poster to this group. Do you have an
incentive to change _your_ anti-social behavior?

(4) You are not net cop. Please use personal email to send critiques of
posting style, rather than posting here.

I realize that me posting to do nothing but criticize your posting style is
perhaps a bit ironic and perhaps unnecessary. But good god, sometimes your
rudeness and pointlessness really goes overboard.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Apr 1 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by John Salerno | last post: by
25 posts views Thread by pamelafluente | last post: by
1 post views Thread by geevaa | last post: by
1 post views Thread by Mike P | last post: by
4 posts views Thread by avicalc | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.