I have a JSON file stored in the same folder as an HTML file for a webpage I'm working on. This HTML file has a script with a function that takes data in a variable in JSON form. I'm having trouble getting the contents of the JSON file into a variable in my HTML file to be used by the function. I am running the HTML file locally.
I've tried the following:
$(function(){
$.getJSON("./data.json", function(jsdata) {
json = jsdata;
console.log(json);
});
});
However, it only results in: XMLHttpRequest cannot load file
. Is there any way to parse a local JSON file in Javascript?
The JSON was validated using http://jsonlint.com/
Using "data.json" gives the same error as before.