views:

473

answers:

2

I am just getting started creating an AJAX application using server side push. I am using Grizzly Comet on Glassfish V2. Almost all the sample applications use IFrames for updating content on the client side. I want to stick to using JavaScript only. Are there any such sample applications (preferably ones that do not use a JavaScript library)?

+3  A: 

The point about the push is that the HTTP request never ends. Not all client implementations handle that correctly. As I see it, it's possible to do it with pure javascript in Firefox with its extensive API, but the XMLHTTPRequest object would timeout and would not be able to stream you the content.

IFrame is good, you could also try the object tag if its about standard compliance.

Before XMLHTTPRequest and Ajax had no name, we used to get data from the servers through IFrames.

Loki
I am using XMLHttpRequest and it works very effectively for comet streaming in Firefox. Sadly I need to have an iframe option as well for IE, but the XMLHttpRequest is much nicer. There is an analogous object in IE, however it can't be accessed in readyState (mode) 3 like the Firefox one can. As a result, you can only utilise it when the stream has finished - hardly useful for comet streaming.
Konrad
+1  A: 

This is how I figured out how to do a push with just javascript and php.

Have javascript do an initial call and load content into a div. Then have the javascript call back to the php and have the php sleep until it see there is a new update. Then send out the data to everyone and call back to php and sleep again.

This allows for long polling and fewer calls back to back. I personally put a time of 5 mins to 30 mins on the php script.

David