0

我在 Angular 中尝试了一件非常简单的事情:通过 $http 调用一个 json 文件 ...

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';
      });
  });

没有成功,总是调用错误函数。json 的路径是正确的(找到了 json)。Firebug 显示 HTTP 200。尝试使用不同的 WebServer(来自 XAMPP 的 Apache,来自 WebStorm 的 IIS Express)。

没有错误消息,但配置显示:

Config: {"method":"GET","transformRequest":[null],"transformResponse":[null],"url":"http://localhost:8080/mydir/myfile.json","headers":{"Accept":"application/json, text/plain, */*"}}
4

1 回答 1

0

经过大量尝试和故障排除后,我现在有了解决方案,将工作代码与非工作代码进行比较:

我的 JSON 文件中存在语法错误...

于 2014-10-14T08:19:55.910 回答