我在 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, */*"}}