0

I've been trying to display JSON data saved on a local directory using Angular but have been getting the dreaded "XMLHttpRequest cannot load file" error because I'm using Chrome. I just need to get this logged on the console and then I can take it from there.

I want to know if there is a good solution to get around this without changing my security setting on Chrome from the command line. Is this a good time to use 'jsonp' instead of 'get'?

Here is my 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);
    })

}])

Here is my 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>

Thanks in advance!

user3802738
  • 117
  • 1
  • 6

0 Answers0