-1

Here is my controller code:

angular.module('navApp', []).controller('blogCtrl', function($scope, $http) {
    $http.get("../json/blogs.json").success(function(response) {$scope.blogs = response.blogs;});
});

How can I load the blogs.json? Blogs.json contains two 'blogs'.

7
  • The way you did is fine. Examine the console log and the network panel of the browser dev tools to see what's wrong (the path of the file probably). Commented Apr 7, 2015 at 18:27
  • XMLHttpRequest cannot load file:///C:/Users/rjohnson/Desktop/practice/json/blogs.json. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource. Commented Apr 7, 2015 at 18:29
  • Shouldn't it be response.data.blogs? Commented Apr 7, 2015 at 18:29
  • 1
    You can't send AJAX requests if your app is served from the file system. You need a web server to serve your app and the JSON files. Commented Apr 7, 2015 at 18:30
  • 1
    @RachelAnn457 set up a local server, and make it run. Commented Apr 7, 2015 at 18:32

1 Answer 1

0

Apparently chrome does not allow local file access due to its policy, I was able to run this request in Firefox.

Sign up to request clarification or add additional context in comments.

1 Comment

You should use a server to expose the JSON files, then is very straight forward: (here)[plnkr.co/edit/5FvKle?p=preview] is a working example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.