Twitter's Streaming API seems to provide a way to receive realtime tweets without constantly polling for new data. Would it be possible to make use of this API using jQuery (or maybe falling back to pure JS)?
As far as I can tell, there's no built-in way for jQuery to stream an HTTP request with JSON. Is that correct, or did I miss something? If this ability isn't built-in, has anyone already tackled this problem with a plugin or example?
Update: From what I can gather, HTML 5's support for WebSockets would likely be the best approach to achieve this. Unfortunately that means mainstream patibility is still at least a few years out. As far as I know, these browser versions currently support WebSockets in some fashion:
- WebKit 5 (Safari/Chrome)
- Firefox 4
- IE9 (Eventually)
Twitter's Streaming API seems to provide a way to receive realtime tweets without constantly polling for new data. Would it be possible to make use of this API using jQuery (or maybe falling back to pure JS)?
As far as I can tell, there's no built-in way for jQuery to stream an HTTP request with JSON. Is that correct, or did I miss something? If this ability isn't built-in, has anyone already tackled this problem with a plugin or example?
Update: From what I can gather, HTML 5's support for WebSockets would likely be the best approach to achieve this. Unfortunately that means mainstream patibility is still at least a few years out. As far as I know, these browser versions currently support WebSockets in some fashion:
- WebKit 5 (Safari/Chrome)
- Firefox 4
- IE9 (Eventually)
- This seems interesting, but at least for the Twitter streams you have to authenticate the request so wouldn't you be exposing your credentials by using JavaScript to get the stream? Otherwise, I think this JSON stream is a pretty cool idea and I'm going to look more into it. – Sandro Commented Jul 22, 2010 at 19:53
- That's a good point that I hadn't discovered yet. In my particular case it wouldn't be a problem since I'm serving the page locally (and only accessible from localhost) and embedding it on my desktop. – Wilco Commented Jul 22, 2010 at 20:06
- Do you have an example utilising the streaming api with websockets or jquery that you could share or provide some useful links that you used? – Sonoman Commented Jul 28, 2011 at 23:15
2 Answers
Reset to default 4HTML5 WebSockets would probably be the best choice.
It is possible to use WebSockets for modern browsers and Flash fallback for unsupported browsers.
This one supports alle browsers: http://jwebsocket/index.htm?page=browsers.htm
You can also try this on, but not tested on IE6: http://github./gimite/web-socket-js
This page might be of interest:
http://ajaxpatterns/HTTP_Streaming#Refactoring_Illustration
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744787781a4593732.html
评论列表(0条)