我在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.尝试使用不同的WebServers(来自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, */*"}}
答案 0 :(得分:0)
我现在有了解决方案,经过大量的尝试和故障排除,将工作代码与非工作代码进行比较:
我的JSON文件中存在语法错误...