views:

47

answers:

1

I have a server page that the when called, generates data. For this example, lets say it outputs one new character every 100 ms, before it finishes after 1-60 seconds.

From the client, I want to be able to read the data from this request with some interval, e.g. every 200 ms. But - and this is important - I can not make another call to this page, it has to be the same request.

The problem is that when I use jQuery.ajax, the success function runs only when the request is finished. This means that I will only get the complete data, and only after (worst case) 60 seconds.

A dream would be if I could have something along this line:

$.ajax({ 
        type: "GET",
        url: "/continouscontent",
        dataType: "html",
        success: function(data) {
                    alert('Done');
                 },
        pollInterval: 200,
        onPoll: function(data) {
                    alert('Current data is: ' + data);
                 }
        });

In the code above, pollInterval and onPoll are of course my speculative ideas.

+1  A: 

In your case, you probably don't want to do polling but pushing from the server which can be achieved using the Bayeux protocol. Take a look at this answer for some pointers:

Tatu Ulmanen
Yes, agree that would be a good solution. However, it's not an option in this case. :/
hbruce
Such persistent sockets are not supported in todays generation of browsers. Also you /continouscontent would have to support such model, and it mans that even long polling is a no-go here.
Tomasz Zielinski