How to refresh a page whenever my json data file changes

前端 未结 5 449
甜味超标
甜味超标 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 14:46

    You want to examine your json file in a very thorough way, in order to understand if it has changed. So what you should do is:

    • use jQuery getJSON() to load the initial data from your json file to a localStorage object.

    then use jQuery getJSON() in a timed loop to get new data from your json file, compare them in-deep and very strict way with a little help from this awsome function posted as an answer in a similar question here. If your localStorage objects, initial JSON and new JSON match Object.deepEquals(initialJSON, newJSON) then no change was made, if not then refresh the page.

提交回复
热议问题