Comet, long polling with jquery tutorial [closed]
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this questionI am looking to add comet long polling functionality to my site by using ajax and jquery as I am not familiar with the javascript prototype framework. However, when I search for this, I always seem to end up with tutorial which use the prototype framework. Does anyone know of any comprehensive tutorial for comet long polling based on jquery and ajax?
Here's a Comet tutorial using jQuery http://screenr.com/SNH
Code used in this tutorial
Cometd has bindings for both the jQuery and Dojo JavaScript libraries. I don't know how comprehensive it is, but it has documentation here: http://cometd.org/documentation/cometd-javascript
Comet and Long polling imply writing part of your code in client side and part on server side. You would need in server CometD or Ape to been able to connect to a Comet server, i find that installing them are usually a pain in the ass.
The option that i have found way more easy is to have Node.js with a "comet" module. Faye(also available for ruby) is a long pole pub sub server quite usefull for chats and Socket Io is a great way to have a page updated constantly to sockets(websockets with flash fallback).
Faye Site:http://faye.jcoglan.com/ Socket Io:http://socket.io/
I have a very simple example here that can get you started with comet. It covers compiling Nginx with the NHPM module and includes code for simple publisher/subscriber roles in jQuery, PHP, and Bash.
http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/
A working example (simple chat) can be found here:
http://cheetah.jamieisaacs.com/
You can force the use of long polling with this
var cometd = $.cometd;
cometd.websocketEnabled = false;
Hope it helps
精彩评论