0

I have a device that upload data every day. The data store in json format and file name using date format (ex: 20181002.json) and a new file will be added to the same folder every day (20181003, 20181004 and so on) for a month and a new folder will be created by device every month.

I want to display the latest data in a table without selecting the filename every day. Is there a way to do that?
This is the filepath I used.

xhr.open('GET', 'database/Dabung/2018/10/20181002.json');
xhr.send();
Waloy
  • 13
  • 7
  • does the code you have work for that one file? is the problem only about change of file name dynamically? – eis Apr 04 '19 at 15:11
  • You need to use `Date` object and construct the file based on current date. – jcubic Apr 04 '19 at 15:11
  • If it was me I would set up a server side endpoint that always returned the latest. Then you have no issues about time it gets updated vs user time etc – charlietfl Apr 04 '19 at 15:16
  • @eis yes my code works for that flie (20181002.json). Yes the problem is how to change file name dynamically. But sometimes the device got errors and not sending data. So if possible I read the newest file instead. Sorry I'm new to web development. – Waloy Apr 04 '19 at 15:19
  • @charlietfl that's interesting but I'm a newbie. I'll learn about it. – Waloy Apr 04 '19 at 15:27
  • Possible duplicate of [Get String in YYYYMMDD format from JS date object?](https://stackoverflow.com/questions/3066586/get-string-in-yyyymmdd-format-from-js-date-object) – eis Apr 04 '19 at 16:06
  • 1
    you can see how to get always current date string form that link ^. However, if you want to dynamically find out the latest, you can't do it with client side javascript very well. You could iterate backwards on a date, but it would be better to make a server side endpoint. – eis Apr 04 '19 at 16:08
  • @eis Thank you so much. I get an idea from that thread. – Waloy Apr 04 '19 at 18:37

0 Answers0