Let's say I have a page that returns a bunch of data slowly over time. Like, this for example:
<?php
$iTime = time();
while(time()-$iTime < 10 ) {
echo "Hello world";
echo str_repeat( ' ', 1024 ) . "<br />";
flush( );
sleep(3);
}
?>
I want to show all the data as it comes in. So it'll update "live". As in, once a line of data is sent, it'll allow me to parse the data and display it?
Is there a way to do this via jquery? I apologize if this has been asked previously
Thanks for your time! :)
Of course, building a basic comet-style long poll is pretty trivial:
PHP:
JavaScript:
take a look at the ajax-http-stream jquery plugin. It extends jquery ajax calls to accept comet style data being streamed from the backend and will call a function
OnDataRecieved
when new data comes in.Well, you're hitting the limitations of the HTTP protocol itself, so this is less jQuery and more about web programming. If you truly need real-time push, then a different protocol is more suited, like XMPP (which several big players use, like Google Wave).
However, with jQuery I'd use normal polling on low-latency, low-power resources to do the job (easy to create static resources that use HTTP caching properly, relying on REST to guide you), so something akin to ;