0

I'm trying a very simple thing in Angular: Call a json file via $http ...

angular.module('testApp', [])
  .controller('TripCtrl', function ($scope, $http) {
      $http.get('http://localhost:8080/mydir/myfile.json').
      success(function (data, status, headers, config) {
          $scope.text = 'Success!';
      }).
      error(function (data, status, headers, config) {
          $scope.text = 'Error';
      });
  });

There is no success, the error function is always called. Path to json is correct (json is found). Firebug shows HTTP 200. Tried with different WebServers (Apache from XAMPP, IIS Express from WebStorm).

There is no error message, but config shows:

Config: {"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:8080/mydir/myfile.json","headers":{"Accept":"application/json, text/plain, */*"}}
mosquito87
  • 4,270
  • 11
  • 46
  • 77
  • What is the error message from angular? – nacholibre Oct 12 '14 at 18:53
  • R u calling it from file:/// with Chrome? – allenhwkim Oct 12 '14 at 19:00
  • Maybe the white space between AngularJS%20Spielwiese is causing problems? Do you see the actual request made from FireBug, does it return 200? – nacholibre Oct 12 '14 at 19:04
  • Why did Config show 'http://localhost:8080/AngularJS%20Spielwiese/js/controllers/trips.json' url? You have requested another url 'http://localhost:8080/mydir/myfile.json'. – Alexey Oct 12 '14 at 20:04
  • Config shows a different url because I simplified the code (shorter path to json). Firebug shows status 200, I can even view the correct json so I think the http side should be okay.I'm calling it with http://localhost... via Firefox. – mosquito87 Oct 13 '14 at 06:35
  • Can you try it from Chrome? – tasseKATT Oct 13 '14 at 08:08
  • Yes, done. Same result. Tried on different PCs. Same result. I only see config. Data, status and headers are null!? – mosquito87 Oct 13 '14 at 09:05

1 Answers1

0

I now have the solution, after a lot of trying and troubleshooting, comparing working code with non-working code:

There was a syntax error in my JSON file ...

mosquito87
  • 4,270
  • 11
  • 46
  • 77