I have a simple folder structure, such as:
project
│
└───data
│ file.json
│
└───js
test.js
I wish to read the file.json
in the test.js
to do some other back-end stuff. Here is a similar (but generic) JSON file:
{"key1": 50, "key2": 6, "key3": 20,
"ke4": 18, "key5": 38, "key6": 30}
So far, i've tried:
var request = new XMLHttpRequest();
request.open("GET", "< path >", false);
request.send(null)
var my_JSON_object = JSON.parse(request.responseText);
alert(my_JSON_object.result[0]);
But it didn't yield results.
I've checked this post and this one. They ask similar question but they're quite old.
So, my question is: How does one do this and is there a new way (e.g. fetch) to do it?