如果数据库更改,则自动刷新内容 [英] Refresh content automatically if the database changes

查看:187
本文介绍了如果数据库更改,则自动刷新内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当mysql数据库表更改时,如何在不刷新页面本身的情况下自动将数据库行(PHP)的值添加到页面?

所以,有点像这样:自动刷新浏览器响应文件系统更改?但是不是在文件系统更改时刷新浏览器,而是在数据库更改时更新内容,而不刷新任何内容.

谢谢.我试图使这一点尽可能清楚.

解决方案

请注意,这是过时的答案.最近这样做的方式是:websockets,服务器发送事件. Firebase是一个很好的例子.您可以在以下位置找到简单的代码示例: https://github.com/laithshadeed/wsk-feedback.在此示例中,您将看到更新的Firebase将通过websocket将事件发送到浏览器,然后UI将更新.

这称为Comet/反向Ajax/HTTP服务器推送 http://en.wikipedia .org/wiki/Comet_(编程).他们是用于执行此操作的许多技术以及许多现有的框架来为您完成此操作.

SO中有关彗星 https://stackoverflow.com/search?q=comet 的很多答案

简单的实现方法是使用javascript setTimeout和setInterval来检查服务器状态,并在mysql上使用触发器/存储过程.

深入了解彗星.有两本很酷的书:

Comet and Reverse Ajax 2008作者Dave Crane

第4章(内容河)-构建实时泰德·罗登(Ted Roden)的《 2010年用户体验》

更新:您可以使用HTML5中的新技术,例如 IE仅在 IE10仅受支持

how can I automatically add the value of a database row (PHP), to the page, without refreshing the page itself, when the mysql database table changes?

So, it is a bit like this: Automatically refresh browser in response to file system changes? , but instead of refreshing the browser with the file system changes, update the content, without refreshing anything, when the databse changes.

Thanks. I have tried to make this as clear as possible.

解决方案

Please note this is outdated answer. Recent ways of doing that is: websockets, server-send events. Nice example of that is Firebase. You can find simple code example in: https://github.com/laithshadeed/wsk-feedback. In this example you will see that updating firebase will send event to the browser via websocket, then the UI will update.

This is called Comet/Reverse Ajax/HTTP server push http://en.wikipedia.org/wiki/Comet_(programming). They are many techniques for doing this as well as many existing frameworks to do it for you.

There are many answers in SO about Comet https://stackoverflow.com/search?q=comet

Simple implementation would be javascript setTimeout and setInterval to check server status, with trigger/stored procedure on mysql.

For depth dive into Comet. There are two cool books about this:

Comet and Reverse Ajax 2008 By Dave Crane

Chapter 4 (River of Content) - Building the Realtime User Experience 2010 By Ted Roden

Update: You may look to the newer techniques in HTML5 like Websockets and Server-sent Events, although IE does not support them well, at the moment Server-sent events is not supported in IE and Web Sockets only supported in IE10

这篇关于如果数据库更改,则自动刷新内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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