I'm trying to make a set of files to be able to send to someone and they can view some stuff in a web browser locally. My code works when viewed using a web server(apache) but if I load it up just as a file, (i.e. file:///C:/Code/Web/test/index.html) it get a cross domain request error from my JavaScript file when loading a JSON file. The HTML, JS, and JSON files are all in the same folder. I'm not sure how this is a cross domain request and why chrome and IE fail at loading the JSON file. Firefox loads it without problem.
The JS I use for loading the file is:
const JSON_FILE = "tin.json";
var xmlhttp;
function webGLStart()
{
fetchDoc(JSON_FILE,loadJSON)
}
function fetchDoc(url,cfunc)
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=cfunc;
xmlhttp.open("GET",url,false);
xmlhttp.send();
}
function loadJSON()
{
if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var input = JSON.parse(xmlhttp.responseText);
displayData(input);
}
}
Nothing really happens in my html page. Its just a canvas where the body calls webGLStart on load.
Is there a way around this or is this something chrome and IE don't allow?