开发者

jQuery: Is it possible to read data continuously from one request?

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 co开发者_JAVA百科mplete 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.


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:

  • Comet and jQuery
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜