Streaming Ajax Response

V

Volte

Hey all. Been looking into this for a while now, got some mock ups and
whatnot. All works well (as far as the server "streaming" the data, via
a sleep and flush method right now just for functionality. Only Ajax
doesnt seem to appreciate it. Still caches the buffer and dumps it out
at once. I was wondering if you guys had any insights on this.

Here is the code.

header("Content-type:
multipart/x-mixed-replace;boundary=endofsection");
print ("\n--endofsection\n");

$pmt = array("-", "\\", "|", "/");

for ($i = 0; $i < 10; $i++)
{
sleep(1);
print ("Content-type: text/plain\n\n");
print ("Part $i\t".$pmt[$i % 4]);
print ("--endofsection\n");
ob_flush();
flush();
}


The AJAX code it s bit extensive, but i basically repeatedly check the
responseText over and over and it only shows up when its completed.

Thanks all, got to run.
 
V

Volte

Hey again. I seem to have gotten it working. Here's the PHP code (I
know, its not JS). Basically just make your ajax return its response
text constantly.

header("Content-type: multipart/x-mixed-replace; boundary=--SEG--");
if ($file = file($_GET['file']))
{
foreach ($file as $i => $line)
{
print ("Content-type: text/plain\n\n");
print ("$line");
print ("--SEG--\n");
ob_flush();
flush();
usleep(500*1000);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top