简体   繁体   English

发布后更新网站上的全局变量

[英]Update global variables on website after post

In index.js I am rendering page with global variables.在 index.js 中,我正在使用全局变量渲染页面。

router.get('/index', function(req, res, next) {

  res.render('index', { title: 'RLH',
  countNumber: countNumber, 
  countReleased: countReleased, 
  countOpen: countOpen
});

in the same index.js I also have:在同一个 index.js 中,我还有:

router.post('/index', function(req, res, next) {
  datatamper = req.body;
  countSev();
  countTickets();
  countTime();

});

On port 3000 I am listening for data, once I get it I am making some calculation and then the page is ready to be opened with global variables.在端口 3000 上,我正在监听数据,一旦我得到它,我就会进行一些计算,然后页面就可以用全局变量打开了。

Clearly this is working just fine to open the page and all data will be here显然这可以很好地打开页面,所有数据都将在这里

On the page I am presenting data like that:在页面上,我正在呈现这样的数据:

<p> <b> Tickets</b>: <span>{{countNumber}}</span></p>

Yet I would like to update just the data on the website by itself after every post(not refreshing the whole page).然而,我想在每次发布后自行更新网站上的数据(而不是刷新整个页面)。

Data by post is coming every minute, yet that might change.邮寄数据每分钟都会出现,但这可能会改变。

You need to implement either some form of longpolling, where your javascript frontend sends requests to the api every so often to check for updates, and then adds them to the page, or use a technology like websockets to get the data as it's updated.您需要实现某种形式的长轮询,您的 javascript 前端每隔一段时间向 api 发送请求以检查更新,然后将它们添加到页面中,或者使用 websockets 之类的技术在更新时获取数据。

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

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