tags:

views:

316

answers:

3

I'm familiar enough with Ajax and JSON that I can send a request and get a parse a JSON request. Ideally I'd like to receive multiple response to periodically update a progress bar. This way clients can have a positive feedback.

I've heard of JSON streams but have not found a good resource on how to implement this. Does anyone know of a good resource or how to do this?

+1  A: 
<script language="JavaScript">
  function doSomething() {
    // do something here...
   }
   setInterval('doSomething()',10000);
<script>

That will call a function every 10 seconds. So you can poll the server every 10 seconds (or 1 second) to get a response on the status of whatever event you're trying to track. Simply put your AJAX call inside that function and it'll send.

Mike Trpcic
A: 

Try looking into the library "comet." It's implements what's known as "reverse AJAX." It'll allow you to send events from the server to the client easily.

The polling suggestion made just before mine, is also perfectly valid.

Pestilence
+1  A: 

JSON is just yet another format of data going over the HTTP protocol (like text, html, pdf, etc). You are probably referring to cometd

http://cometdproject.dojotoolkit.org/

This allows you to open a persistent connection and push data from the server to the client (ie stream it). Any format is valid to push, the client just needs to understand it.

mlathe