How to refresh a page whenever my json data file changes

前端 未结 5 450
甜味超标
甜味超标 2020-12-29 14:26

So I\'ve got this local file named \'data.json\' containing various data. I want to refresh my page only when some data in the json file changes. Appreciate your help if you

5条回答
  •  执笔经年
    2020-12-29 15:03

    If you're using Node, it has a built-in fs.watch() function that basically checks to see if/when a file has changed. Otherwise, you'd likely want a setInterval to periodically get the JSON file via an AJAX call and update your variables/DOM. You could compare the old JSON object to the new one and if they're different, update the DOM/variables with the new data.

提交回复
热议问题