Cross-browser implementation of “HTTP Streaming” (push) AJAX pattern

前端 未结 2 1011
有刺的猬
有刺的猬 2020-12-04 20:31

Client request web page from server. Clent then requests for extra calculations to be done; server performs series of calculations and sends partial results as soon as they

2条回答
  •  心在旅途
    2020-12-04 21:05

    The solution you linked to is not AJAX at all, actually. They call it HTTP Streaming but it's essentially just long polling.

    In the example they link to, you can see for yourself quite easily with firebug. Turn on the Net panel - there are no XHR entries, but it takes just a hair over 10 seconds to load the original page. That's because they're using PHP behind the scenes to delay the output of the HTML. This is the essence of long polling - the HTTP connection stays open, and the periodic HTML sent back is javascript commands.

    You can opt to do the polling completely on the client side, though, with setTimeout() or setInterval()

    A jQuery example

    
    

提交回复
热议问题