JQuery.getJSON() reading a local file

user1167650 picture user1167650 · Jul 2, 2012 · Viewed 29.2k times · Source

How do you read a file in the current directory using JQuery.getJSON()?

I'm trying something simple (with my data.json file in the same directory as my html file):

$.getJSON("./data.json")

and I get the error:

XMLHttpRequest cannot load file:///C:/Projects/test/data.json. Origin null is not allowed by Access-Control-Allow-Origin.

I've tried all sorts of combinations of path, but it doesn't seem to work...

EDIT: I'm using Chrome, but I'd like to work in all browsers...

Answer

ephemient picture ephemient · Jul 2, 2012

If you are using Google Chrome, it is intentional that AJAX on file:/// paths never works.

crbug/40787