Javascript Comet,使用jquery教程进行长轮询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3940732/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Comet, long polling with jquery tutorial
提问by oshirowanen
I 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?
我希望通过使用 ajax 和 jquery 向我的网站添加 Comet 长轮询功能,因为我不熟悉 javascript 原型框架。然而,当我搜索这个时,我似乎总是以使用原型框架的教程结束。有没有人知道基于 jquery 和 ajax 的彗星长轮询的综合教程?
回答by
Here's a Comet tutorial using jQuery http://screenr.com/SNH
Codeused in this tutorial
这是一个 Comet 教程,使用 jQuery http://screenr.com/SNH本教程中 使用的
代码
回答by Ash
Cometdhas 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
Cometd绑定了 jQuery 和 Dojo JavaScript 库。我不知道它有多全面,但这里有文档:http: //cometd.org/documentation/cometd-javascript
回答by Siedrix
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.
Comet 和 Long 轮询意味着在客户端编写部分代码,在服务器端编写部分代码。您需要在服务器 CometD 或 Ape 中才能连接到 Comet 服务器,我发现安装它们通常很麻烦。
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).
我发现更简单的选择是让 Node.js 带有一个“彗星”模块。Faye(也可用于 ruby)是一个长杆 pub 子服务器,对于聊天非常有用,而 Socket Io 是将页面不断更新到套接字(具有闪存回退的 websockets)的好方法。
Faye Site:http://faye.jcoglan.com/ Socket Io:http://socket.io/
Faye 站点:http://faye.jcoglan.com/ Socket Io:http://socket.io/
回答by Jamie
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.
我这里有一个非常简单的例子,可以让你开始使用 Comet。它涵盖了使用 NHPM 模块编译 Nginx,并包括用于 jQuery、PHP 和 Bash 中的简单发布者/订阅者角色的代码。
http://blog.jamieisaacs.com/2010/08/27/comet-with-nginx-and-jquery/
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/
可以在此处找到一个工作示例(简单聊天):http:
//cheetah.jamieisaacs.com/
回答by Pablo Johnson
You can force the use of long polling with this
您可以强制使用长轮询
var cometd = $.cometd;
cometd.websocketEnabled = false;
Hope it helps
希望能帮助到你