I am faced with a straightforward folder structure, it looks like this:
project
│
└───data
│ file.json
│
└───js
test.js
My goal is to access the content of file.json
within the test.js
file in order to perform some additional back-end operations. Here's an example of a JSON file (the actual content is generic):
{"key1": 50, "key2": 6, "key3": 20,
"ke4": 18, "key5": 38, "key6": 30}
Thus far, my attempt has been:
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]);
Unfortunately, this approach did not produce the desired outcome.
I have referred to these posts: post and one. They address similar issues, but they are outdated.
Consequently, my question is: What is the correct method for achieving this task, and is there a more modern approach (e.g., fetch) available?