I am parsing a json file in my Javascript code like below.
$.getJSON('file:///dashboard.json', function (json) {
However, it throws
XMLHttpRequest
cannot load file:///dashboard.json
. Cross origin requests
are only supported for HTTP
.
I've been looking for solutions for almost 7 hours collectively, but most suggestions were to use this:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
or
open -b com.google.chrome --args --allow-file-access-from-files
and even when I opened Chrome with the second command, the same Cross origin request error is thrown.
The first command does not even run, as you can see below.
$ /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
[708:1287:0401/174956:ERROR:process_singleton_mac.cc(103)] Unable to obtain profile lock.
$ [0401/174957:ERROR:mach_broker_mac.mm(152)] Failed to look up named parent port: 0x44e unknown error code
I tried launching a server with this file, on port 8000, and accessing it by providing url http://localhost:8000/dashboard.json
, but it does not fix Cross origin request error. (My web app runs on port 8080
).
What is the problem? How can I fix this? Please help me. Thank you.