Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > XMLHTTPRequest streaming data

Reply
Thread Tools

XMLHTTPRequest streaming data

 
 
googlegroups@scottsavarese.com
Guest
Posts: n/a
 
      06-22-2005
I am playing with the XMLHTTPRequest method to perform client/server
transactions. I have it set up right now so that when readyState is 4,
it takes the XML and processes it. This works great until there is alot
of data. In that case, the user will have to wait for the data to come
back which may take a minute or so.

I don't want the user to have to wait. Is it possible for javascript to
periodically (while still receiving more data) stop and display what it
has received thus far? I guess this would be considered a type of
streaming.

In mozilla/firefox, I have read that I can use readyState 3 to run my
callback function every 4096 bytes. I can then take those 4K, parse
them, and then continue on. However I have also read that IE cannot do
this. Since I need this to work in IE, is there a workaround?

Thanks,
Scott

 
Reply With Quote
 
 
 
 
Matt Kruse
Guest
Posts: n/a
 
      06-22-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I don't want the user to have to wait. Is it possible for javascript
> to periodically (while still receiving more data) stop and display
> what it has received thus far?


Not that I know of.
One suggestion - use JSON instead of XML. Or use your own compact data
structure.

XML is verbose, and you may be able to cut down your transmission time if
you use a data format that is more compact.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      06-22-2005


(E-Mail Removed) wrote:


> In mozilla/firefox, I have read that I can use readyState 3 to run my
> callback function every 4096 bytes. I can then take those 4K, parse
> them, and then continue on. However I have also read that IE cannot do
> this. Since I need this to work in IE, is there a workaround?


You should be able to access responseText once readyState gives you the
value 3 for interactive.
From the MSXML docs for XMLHTTP:

(3) INTERACTIVE Some data has been received. You can call the
responseBody and responseText properties to get the current partial
results.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      06-22-2005


Martin Honnen wrote:


> You should be able to access responseText once readyState gives you the
> value 3 for interactive.
> From the MSXML docs for XMLHTTP:
>
> (3) INTERACTIVE Some data has been received. You can call the
> responseBody and responseText properties to get the current partial
> results.


I have done some tests here trying to access responseText when
readyState is signalled as 3 but unfortunately MSXML then always gives
an exception that the data necessary is not yet available so in this
case it looks like the docs are promising more than is possible.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Matt Kruse
Guest
Posts: n/a
 
      06-22-2005
Martin Honnen wrote:
> (3) INTERACTIVE Some data has been received. You can call the
> responseBody and responseText properties to get the current partial
> results.


However, with XML it needs to be well-formed and parsed before being
available, afaik.
You can get to the responseText, but it won't be XML that can be
manipulated.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


 
Reply With Quote
 
googlegroups@scottsavarese.com
Guest
Posts: n/a
 
      06-22-2005
Matt Kruse wrote:
> Not that I know of.
> One suggestion - use JSON instead of XML. Or use your own compact data
> structure.


I'll look into JSON. Right now our XML is pretty compact. The structure
is very little overhead as compared to the data itself. I am more
worried by the shear number of data rows we may return than anything
else.

I was playing around with Mozilla. It doesn't seem to hard to keep
track of how much data I've read so far and use substring to extract
the latest. Then parse the latest information and present it to the
user.

However with IE, I can't use the readyState variable. Plus I tried
using a timer (every second) to read the responseText and IE comes back
with an error. Is there anyway to get the partial response from IE or
do I have to wait until it completes? Is there any hack I can do to IE
to get it to work?

Thanks,
Scott

 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      06-22-2005
On 22 Jun 2005 12:40:41 -0700, (E-Mail Removed) wrote:

>However with IE, I can't use the readyState variable. Plus I tried
>using a timer (every second) to read the responseText and IE comes back
>with an error. Is there anyway to get the partial response from IE or
>do I have to wait until it completes? Is there any hack I can do to IE
>to get it to work?


No, just use the IFRAME remote scripting method and JSON, it's much
more reliable and cross-platform for achieving what you want, although
it's the server that has to do the breaking up.

Jim.
 
Reply With Quote
 
googlegroups@scottsavarese.com
Guest
Posts: n/a
 
      06-22-2005
Martin Honnen wrote:
> I have done some tests here trying to access responseText when
> readyState is signalled as 3 but unfortunately MSXML then always gives
> an exception that the data necessary is not yet available so in this
> case it looks like the docs are promising more than is possible.


I get the same thing... That is exactly what I am trying to get around.

Scott

 
Reply With Quote
 
googlegroups@scottsavarese.com
Guest
Posts: n/a
 
      06-22-2005
Jim Ley wrote:
> No, just use the IFRAME remote scripting method and JSON, it's much
> more reliable and cross-platform for achieving what you want, although
> it's the server that has to do the breaking up.


I really like the idea of JSON. Unfortunately in this case, I need my
protocol to be XML. The code can't be language specific. If I was just
using a web browser to obtain the information from the server, then
JSON can be used, and may even be better, however I also have a perl
client side module, and I have a feeling my users are going to want a
Java one as well. How is JSON with security... I run the returned value
in a eval block. Of the examples I've seen everyone seems to trust that
the data returned is valid and not harmful. Can you craft a JSON reply
that does something malicious?

As for the IFRAME piece, I did some research on it... Is there an
example on line of people doing the type of streaming that I am looking
for? Also, it looks like the IFRAME seems to imply a need to use GET as
opposed to POST (as it updates the history). Is that true?

Scott

 
Reply With Quote
 
Jim Ley
Guest
Posts: n/a
 
      06-22-2005
On 22 Jun 2005 13:37:20 -0700, (E-Mail Removed) wrote:

>Jim Ley wrote:
>> No, just use the IFRAME remote scripting method and JSON, it's much
>> more reliable and cross-platform for achieving what you want, although
>> it's the server that has to do the breaking up.

>
>I really like the idea of JSON. Unfortunately in this case, I need my
>protocol to be XML.


No, you need to provide an XML protocol, that doesn't mean the one you
provide to your website is XML, a server XML->json is entirely
appropriate solution - especially as IFRAME's (which require JSON to
do this) are the only way you're going to get the incremental approach
in IE.

As for a link, no idea, you just need to write out an HTML document
with

<script type="text/javascript">
.... block 1
</script>

<script type="text/javascript">
.... block 2
</script>

<script type="text/javascript">
.... block 3
</script>

etc.

Jim.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Xmlhttprequest - response to transfer data rwiegel@iastate.edu XML 1 05-22-2007 07:00 AM
XMLHttpRequest gets data to display in element but data gets appended not replaces previous! libsfan01 Javascript 5 12-20-2006 06:25 AM
Passing data via XMLHTTPRequest... How do YOU do it? Noozer ASP General 7 04-15-2006 09:19 AM
How to read the streaming data from IE xmlhttprequest object Vijay Javascript 3 04-03-2006 10:29 AM



Advertisments