jQuery read AJAX stream incrementally?

This is quite straightforward when outputting text or HTML. Below is an example. (You’ll run into issues if trying to output JSON however, which I’ll tackle further down.) PHP FILE header(‘Content-type: text/html; charset=utf-8’); function output($val) { echo $val; flush(); ob_flush(); usleep(500000); } output(‘Begin… (counting to 10)’); for( $i = 0 ; $i < 10 ; … Read more

What are Long-Polling, Websockets, Server-Sent Events (SSE) and Comet?

In the examples below the client is the browser and the server is the webserver hosting the website. Before you can understand these technologies, you have to understand classic HTTP web traffic first. Regular HTTP: A client requests a webpage from a server. The server calculates the response The server sends the response to the … Read more