I am new to scripting languages. I have a new.json file and I want to load in gary.html HTML file. I do not want to run gary.html file on server. I want to run it locally on my machine.
When my HTML file loads the new.json file using $.getJSON, I get a blank screen and when I checked on console I get the error:
jquery-3.1.0.js:9392 XMLHttpRequest cannot load file:///C:/Users/Gary/Desktop/new.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.`
and this my loading code
function show() {
//read(a)
var myItems;
$.getJSON('new.json', function(data) {
myItems = data.a;
read(myItems)
});
}
When I googled for this error, people suggest to me run this file on firefox, or execute this chrome --allow-file-access-from-files. The file is loading in firefox and when I am executing the chrome --allow-file-access-from-files, the File also loads in chrome.
My main concern is that when I distribute the new.json and gary.html file to others then others may or may not have firefox or chrome's chrome --allow-file-access-from-files permission. I just want user to click on gary.html and it loads the data of new.json file.
How can I achieve that?
new.jsonfile in the page using an extra<script />tagnew.jsonto assign the object to a variable which you can parse and access as you normally would any standard object without the need for the AJAX callvar data = {"a": [ {"name":"avc"}, {"name":"Anna"}, {"name":"Peter"}]}and you may accessdata.adirectly without invoking $.getJSON api