0
    $( document ).ready(function() {
      $.getJSON("./data/test.json", function(json) {
        console.log(json); // this will show the info it in firebug console
      });
    });

How can I load a local file that is not being hosted on a webserver?


I get an error in the console

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

The file is being hosted on my C drive

software is fun
  • 7,286
  • 18
  • 71
  • 129
  • check the browser console, ctrl+shift+j – ameenulla0007 Feb 03 '16 at 16:17
  • Maybe if you use `../data/test.json` instead – Hackerman Feb 03 '16 at 16:17
  • Which browser was used to request data ? – guest271314 Feb 03 '16 at 16:19
  • Testing and Developing on Chrome. Deployed with IE11 – software is fun Feb 03 '16 at 16:20
  • @softwareisfun See http://stackoverflow.com/questions/32996001/jquery-load-only-working-in-firefox/32996188#32996188 – guest271314 Feb 03 '16 at 16:21
  • yea but that wont help me when im launching in IE 11 – software is fun Feb 03 '16 at 16:22
  • _"yea but that wont help me when im launching in IE 11"_ Does ie11 log same error at `console` ? – guest271314 Feb 03 '16 at 16:23
  • even after launching chrome --allow-file-access-from-files, same issue – software is fun Feb 03 '16 at 16:24
  • Oddly it doesnt log any error but the contents of my JSON file do not display in the console – software is fun Feb 03 '16 at 16:25
  • _"even after launching chrome --allow-file-access-from-files, same issue"_ Not viewed this occurring previously at chromium or chrome. Can include launcher lines at Question ? – guest271314 Feb 03 '16 at 16:25
  • _"Oddly it doesnt log any error but the contents of my JSON file do not display in the console"_ Try chaining `.fail()` to `$.getJSON()` call to log errors; also try using full path to json file – guest271314 Feb 03 '16 at 16:27
  • I changed the Browser emulation in IE11 to IE10 and my contents from my JSON file appeared. When it's Edge (default), nothing appears. – software is fun Feb 03 '16 at 16:27
  • _"I changed the Browser emulation in IE11 to IE10"_ Is Question concerning chrome or ie browser ? – guest271314 Feb 03 '16 at 16:31
  • Using IE11, I pressed F12 then changed the browser to 10. My JSON spit out the contents as I had expected. However the issues are that it's not doing the same in Chrome or IE11. This HTML file will be deployed on 800 PC's and we can't manually change each browser emulation to 10 or install Chrome – software is fun Feb 03 '16 at 16:33
  • _"This HTML file will be deployed on 800 PC's and we can't manually change each browser emulation to 10 or install Chrome"_ Is browser being run in a `vm` ? Not certain interpret Question correctly ? Are there both chrome and ie browsers used at the n-PC's ? – guest271314 Feb 03 '16 at 16:35
  • The PC's are not running in a VM. Only on my development machine, I have both browsers. I prefer Chrome's debugging tools over IE. However when the product is ready, it will need to launch in IE11 for Windows 7 – software is fun Feb 03 '16 at 16:37
  • _"However when the product is ready, it will need to launch in IE11 for Windows 7"_ Why test on chrome if application requires *indows , ie 11 environment ? See also https://www.browserstack.com/ – guest271314 Feb 03 '16 at 16:38
  • Im developing in Chrome because I prefer the tools better. I am testing on both. Usually my apps work in both. But for some reason I can't load the JSON file locally – software is fun Feb 03 '16 at 16:43
  • What is purpose of testing loading local file if application is for consumption over n PC's ? Will all n-PC's be loading file locally in same manner as test at chrome ? Or, will all n-PC's be loading same external json file ? – guest271314 Feb 03 '16 at 16:45
  • Yes, they will use a storage server. \\Server\Path\WebApp\data\test.json – software is fun Feb 03 '16 at 16:50
  • _"Yes"_ file will be at each individual PC ? – guest271314 Feb 03 '16 at 16:52
  • the file will be accessible via shared file on a server. The actual html, css, js will not be on the local HD. In either case, there is no web server – software is fun Feb 03 '16 at 16:53
  • Tried using a `Worker` to serve file ? – guest271314 Feb 03 '16 at 16:56
  • how would that help? Web Worker appears to be the same as threading – software is fun Feb 03 '16 at 16:57
  • Could embed json file within `html` file, serve json file from same `html` document to itself. This could be done without web worker as well – guest271314 Feb 03 '16 at 17:00
  • I didn't think about that. Would it go in my script tag or somewhere else? – software is fun Feb 03 '16 at 17:01
  • See http://stackoverflow.com/questions/35116459/how-to-make-a-html-form-interactive/ using `script` elements. Another option could be to embed json file within `data-*` attribute of `html` or other element. Alternatively, could use `shadowDOM` , `template` element – guest271314 Feb 03 '16 at 17:02

0 Answers0