简体   繁体   English

PHP MySQL:如何仅在数据库上的数据更改时自动刷新数据

[英]PHP MySQL : How to make an auto refresh data only when data changed on database

Usually I make content refresh automatically with the javascript function using setInterval.通常我使用 setInterval 使用 javascript function 自动刷新内容。 But it seems ineffective because every second the content must be reloaded will take up a lot of resources.但这似乎无效,因为必须重新加载内容的每一秒都会占用大量资源。

Therefore if there is another alternative to creating an automatic refresh function only when the data has changed in the database.因此,仅当数据库中的数据发生更改时,如果有另一种替代方法来创建自动刷新 function。

One way to update your data would be to use Ajax in the frontend to request the data every few seconds and update it instead of reloading the page.更新数据的一种方法是在前端使用 Ajax 每隔几秒请求一次数据并更新它,而不是重新加载页面。 Otherwise, you should check out socket.io (websockets)否则,您应该查看socket.io (websockets)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM