2

My application works just perfectly fine on localhost, but when I output it to my /Build directory and try and open the index.html file, I get this error when trying to retrieve some JSON data over $http:

XMLHttpRequest cannot load file:///Users/realph/Desktop/gulp-test/Build/js/data/results.json

Any idea why this is happening? I've never run into this issue before and can't work out what I'm doing wrong...

My $http service looks like this:

$http.get('./js/data/results.json')
.success(function(data, status, headers, config) {
  $scope.data = data;
}).
error(function(data, status, headers, config) {
  console.log("Error loading results.json!");
});

Any help is appreciated. Thanks in advance!

realph
  • 4,481
  • 13
  • 49
  • 104
  • 2
    Does [this question](http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-allow-origin-for-file) help you? May be as simple as allowing `file://` URLs in your browser. – Alex Apr 15 '15 at 22:07
  • 1
    Have you tried removing the "./" from the front of your URL, so instead of ./js/data/results.json, how about just js/data/results.json?? – Severun Apr 15 '15 at 22:25
  • yes, that dot in url is smth strange – Petr Averyanov Apr 15 '15 at 22:28
  • Tried removing the "./" to no avail... – realph Apr 15 '15 at 22:29
  • as the first comment said: either run it from a local webserver, or enable file urls – Austin Greco Apr 15 '15 at 22:33
  • @AustinGreco Is there not a way around this? It's a coding exercise that I have to submit, and they seem to think the app should work once you open the `index.html` file in your browser. I'm assuming that means without a local webserver... – realph Apr 15 '15 at 22:35
  • I see the path says `gulp-test`, is there a `gulpfile.js`? The typical solution is to just run a local webserver, and gulp typically has a task like `gulp serve`. – Austin Greco Apr 15 '15 at 22:43

0 Answers0