我一直在尝试使用Angular显示保存在本地目录中的JSON数据但是已经得到了可怕的" XMLHttpRequest无法加载文件"错误,因为我使用的是Chrome。我只需要在控制台上登录,然后我可以从那里拿走它。
我想知道是否有一个很好的解决方案可以解决这个问题,而无需在命令行上更改Chrome上的安全设置。这是一个使用' jsonp'而不是'得到'?
这是我的app.js:
angular
.module('myApp', [])
.controller('MainCtrl', ['$scope', '$http', function($scope, $http){
$http.get('data/posts.json').success(function(data){
$scope.data = data
console.log(data);
})
}])
这是我的HTML:
<!DOCTYPE HTML >
<html>
<head>
<title>The network</title>
<link rel="stylesheet" type="text/css" href="normalize.css" />
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.15/angular.js"></script>
<script type="text/javascript" src="javascripts/ng-app/app.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller='MainCtrl'>
{{data}}
</div>
</body>
</html>
提前致谢!