使用 Rails 和 jQuery 类似于 Facebook 的推送式通知 [英] push-style notifications similar to Facebook with Rails and jQuery

查看:32
本文介绍了使用 Rails 和 jQuery 类似于 Facebook 的推送式通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个类似于 Facebook 的推送通知系统.每当 Facebook 想要告诉你一些事情(比如有人对帖子发表评论、标记你等)时,你会在屏幕的左下角看到一个小通知.它淡入淡出.

I want to create a push notification system like Facebook. Whenever Facebook wants to tell you something (like that someone commented on a post, tagged you, etc), you'll see a small notification show up in the bottom left corner of the screen. It fades in and fades out.

如何使用 jQuery 和 Rails 构建这样的系统?它是如何工作的?JS 是否不断询问服务器,有新的通知吗?"或者服务器是否以某种方式推送到这个服务.

How do I build a system like this with jQuery and Rails? How does it even work? Does JS constantly ask the server, "is there a new notification?" or does the server somehow push to this service.

现在,如果用户向另一个用户发送消息(例如),我可以向用户的队列添加一条通知,说您有一条新消息",但它不会出现,直到页面重新加载...

Right now, if a user sends another user a message (for example), I can add a notification to the user's queue saying "you have a new message", but it won't appear until a page reload...

推荐答案

Juggernaut 看起来真的很酷,我很久以前看过demo,现在在node.js上重写了.好的.你必须安装 redis 和 node.js 并运行 node.js 服务器,剩下的就很简单了.

Juggernaut looks really cool, i saw it demoed a long time ago, now it is rewritten on top of node.js. Nice. You have to install redis and node.js and run a node.js server and the rest is dead-easy.

Pusherapp.com 看起来也很酷,它是付费的,但至少您不必安装和运行额外的服务(以及守护程序、扩展它们,......).

Pusherapp.com also looks cool, it is paying, but at least you don't have to install and run extra services (and daemonise, scale them, ...).

但是,如果负载不是太大,我更愿意保持简单,并且只使用 javascript 进行轮询.您可以轻松编写自己的(不太难),但是对于 jquery 已经存在一些非常好的插件.例如 PeriodicalUpdater.

But, if the load is not too big, i would prefer to keep things simple, and just poll using javascript. You could easily write your own (it is not too hard), but some very good plugins already exist for jquery. For instance PeriodicalUpdater.

这篇关于使用 Rails 和 jQuery 类似于 Facebook 的推送式通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆