- 1
How to load up a json file in HTML
i am trying to store data in a JSON file but i can import/load it in the HTML page. ive already tried 'const file = require("./file.json")' and 'const file = import("./file.json")' but when i open the page, and see inspects menu's console the require code results in "require is not a function" -_- and the import results in "access denied to file by null" or something like that ... can anyone please tell how can i load json file in html....
3 Respostas
0
1) send an XmlHttpRequest for the json file url
2) get the responseText attribute for the request that contain the file body
3) use JSON.parse for parse json text in a js object
- 1
also tried banging my head against the wall ... didnt work either
- 1
thanks