I have a local .json formated file that I like to get it via $.getJSON as follows:
$.getJSON('D:/Data/cpu.json', function(data) {
this does not seem to be working. Any ideas what might be the case?
I have a local .json formated file that I like to get it via $.getJSON as follows:
$.getJSON('D:/Data/cpu.json', function(data) {
this does not seem to be working. Any ideas what might be the case?
What you need to do use a "file URI scheme".
The file URL scheme is a URL scheme specified in RFC 1630 and RFC 1738, typically used to retrieve files from within one's own computer.
It looks something like this:
file://path/to/your/file
So, for your example:
$.getJSON('file://D:/Data/cpu.json', function(data) { ... } );
There are some considerations to be made when using a windows machine. You can take a look at the wiki article I linked to. It is related to the colon within the file path.
One possible reason will be CORS.
The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin.
Means this is not possible with the system file, you have to use it in a web server.