当 mysql 数据库表发生变化时,如何在不刷新页面本身的情况下自动将数据库行 (PHP) 的值添加到页面?
所以,有点像这样:Automatically refresh browser in response to file system changes? , 但是当数据库发生变化时,不是用文件系统的变化来刷新浏览器,而是更新内容,而不刷新任何东西。
谢谢。我已尝试尽可能清楚地说明这一点。
最佳答案
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.
这称为 Comet/Reverse Ajax/HTTP 服务器推送 http://en.wikipedia.org/wiki/Comet_(programming) .有许多技术可以做到这一点,还有许多现有框架可以为您做到这一点。
关于 Comet https://stackoverflow.com/search?q=comet SO 中有很多答案
简单的实现是使用 javascript setTimeout 和 setInterval 来检查服务器状态,在 mysql 上使用触发器/存储过程。
深入探索 Comet。有两本关于此的好书:
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
关于php - 如果数据库发生变化,自动刷新内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8100594/