简体   繁体   中英

Update global variables on website after post

In index.js I am rendering page with global variables.

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:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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