使用Javascript(真正)实时更新数据 [英] Update data in (really) real-time with Javascript

查看:424
本文介绍了使用Javascript(真正)实时更新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为需要在全屏模式下运行的Web艺术应用程序构建一个控制面板,因此控制颜色和速度值之类的所有面板都必须位于其他窗口中.

I want to build a control panel for a web art application that needs to run in fullscreen, so all this panel, that controls stuff like colors and speed values, have to be located at a different window.

我的想法是拥有一个存储所有这些值的数据库,当我在控制面板窗口中进行更改时,应用程序窗口中的相应变量也将被更新.因此,这基本上是一个实时更新,我可以使用AJAX设置时间间隔以不断检查更改,我的问题是:我等不及30秒左右的更新,我想每隔一秒钟的AJAX请求将是不可能的.

My idea is to have a database storing all these values and when I make a change in the control panel window the corresponding variable in the application window gets updated too. So, it's basically a real-time update that I could do with AJAX setting a interval to keep checking for changes BUT my problem is: I can't wait 30 seconds or so for the update to happen and I guess a every-1-second AJAX request would be impossible.

最后一个问题:是否有一种方法可以创建一种侦听器来更改数据库中的更改,并仅在控制面板中更改某些值后立即在主应用程序中触发更新事件?Angular或其他框架是否具有此功能?

Final question: is there a way to create a sort of a listener to changes in the database and fire the update event in the main application only immediately after I change some value in the control panel? Does Angular or another framework have this capability?

(很抱歉,冗长的解释,但我希望通过提供上下文[:)使我的问题更清楚

(Sorry for the long explanation, but I hope my question is clearer by offering the context [: )

推荐答案

基于Web套接字的应用程序将具有此优势.这样在后端会带来更多的复杂性,但是具有使您的应用程序尽可能合理地接近实时的好处.

A web socket powered application would have this benefit. This carries a bit more complexity on the back end, but has the benefit of making your application as close to real-time as can be reasonably expected.

Mozilla开发网络在websocket上有一些很好的文档.

The Mozilla Development Network has some good documentation on websockets.

在前端,WebSocket对象应可在大多数现代浏览器上为您工作.

On the front end, the WebSocket object should work for you on most modern browsers.

我不确定您的后端是什么,但是对于Node.js和 Socket.IO 用于Python的href ="http://www.tornadoweb.org/en/stable/" rel ="nofollow"> Tornado 将使您的应用程序具有网络套接字功能

I'm not sure what your back end is written in, but Socket.IO for Node.js and Tornado for Python will make your applications web-socket capable

这篇关于使用Javascript(真正)实时更新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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