Search code examples
javascriptjsonajaxjqxhr

Is it possible to use xhr for local files?


I can't find any recent answers to this, is it possible to load up a local file using AJAX request. So in my site I have a file called data.json on my web server is it possible to request the date from my Js file using a relative path rather than using its web accessible url and therefore incurring a speed cost.


Solution

  • A site with an origin http://…, https://…, … cannot access content via file:///…. Otherwise nothing could stop any arbitrary website from stealing your local data. Probably the buzzword you are looking for is localStorage.

    See also: noscript's ABE, a popular addon that makes the separation between local and remote content even stricter.

    See also: “Firefox exploit found in the wild”, when the separation fails.