实时通知jQuery

编程入门 行业动态 更新时间:2024-10-25 00:25:58
本文介绍了实时通知jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有人可以引导我正确地进行实时通知吗

Can someone lead me down the right way to make a live notifications

例如,知道何时在Mysql中添加了新行

e.g Knowing when a new Row in Added in Mysql

了解php文件是否已更改???

know if a php file has changed ???

我应该怎么做?

推荐答案

您可以使用setInterval()例行检查服务器是否有更新,或者可以对JavaScript使用长轮询. setInterval()的好处是它不会使连接在服务器上打开的时间过长,但是您可能在两次服务器调用之间的停机时间"内进行了更新.长轮询将为您提供近乎即时的更新,因为它会等待连接打开,直到收到新信息.但是显然,不利的一面是,您到处都有连接处于打开状态.

You could routinely check the server for updates using setInterval(), or you could employ long-polling with javascript. The benefit of setInterval() is that it doesn't keep connections opened on your server for too long, but you may have updates during the 'downtime' between server-calls. Long-polling will give you near-instant updates, as it waits with the connection opened until it receives new information. But obviously, the down side is that you've got connections staying opened all over the place.

setInterval(function(){ $.get("updates.php", {}, function(results){ if ($(results).length) { $("results").each(function(){ // do something with update messages }); } }); }, 30000); // Every 30 seconds.

使用PHP/jQuery示例进行长轮询:

您可以在 blog.perplexedlabs/2009/05/04/php-jquery-ajax-javascript-long-polling/

更多推荐

实时通知jQuery

本文发布于:2023-11-16 23:10:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607879.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实时   通知   jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!