views:

218

answers:

2

Hi

I have created a page in which I use the PHP function flush(), to output data to the browser the second the data is echoed. I'm also calling this page using jQuery's ajax function. It works, but jQuery doesn't output anything until the entire page has executed, which kind of removes the functionality of flush().

How can I fix this?

My ajax call looks like this:

jQuery.ajax({
        type: "get",
        url: url,
        data: postdata,
        success: function(retval) {
             jQuery('#retdiv").html(retval);
        }
})
+1  A: 

jQuery needs to wait for the connection to close before it can insert the html onto the page -- it can't display it progressively (it wouldn't make any sense).

Jhong
Can you think of a different way to do it?
MrAwesome
@MrAwesome What are you trying to accomplish?
quantumSoup
@MrAwesome: Sure, just send what you want to send, but include a key or marker, and just end the script. The client then sends back another request (with the marker), and your back-end script carries on processing the next step.
Jhong
@Jhong: Have you got an example?
MrAwesome
+2  A: 

Here you have 2 plugins for streaming:

JQUERY AJAX HTTP STREAM and JSTREAMPLUG.

http://plugins.jquery.com/taxonomy/term/1840

"This plugin allows for a constant connection with a server keeping content continuously updated with the latest content using one http request. It extends the $.ajax, $.get, and $.post functions to allow for streaming."

Sebastián Grignoli