Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "stream" json from server to client using javascript

Tags:

json

ajax

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?

like image 824
atodd Avatar asked Jan 28 '10 20:01

atodd


2 Answers

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

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.

like image 152
mlathe Avatar answered Oct 13 '22 21:10

mlathe


Found a technique called page streaming.

Basically you write <script>some js</script> entries into the persistent connection and flush them into the network interface. As browser receives that, it will parse and execute the script.

like image 43
Evgeny Avatar answered Oct 13 '22 20:10

Evgeny