0

I want to access json file in angular.js by using the following code but I am unable to access the code because of the below mentioned shown error. Help would be appreciated.!!

module :

angular.module("demoApp", ['demoApp.factory','demoApp.controllers']);

Factory:

angular.module('demoApp.factory', []).
factory('getJsonDataFactory',function($http){
    return{
    getData : function() {
        return $http.get('mapData.json');
    }
 }
});

controller :

angular.module('demoApp.controllers', []).
  controller('GetJsonController', function($scope,$http,getJsonDataFactory) {
              $scope.markers = [];  
              getJsonDataFactory.getData().success(function(data){
                $scope.photos=data;
            });
        });

Error : In firefox:

 "Access to restricted URI denied" code: "1012"


return logFn.apply(console, args)

In Chrome :`

Origin null is not allowed by Access-Control-Allow-Origin.
9
  • is it running on a server ? Commented Oct 1, 2013 at 12:43
  • What happen when just accessing the file via browser? Commented Oct 1, 2013 at 12:44
  • no.. this is not running on a server Commented Oct 1, 2013 at 12:46
  • Then need to change allow-file-access-from-files(chrome) Commented Oct 1, 2013 at 12:46
  • vittore - when access through browser , i am getting these errors shown up Commented Oct 1, 2013 at 12:48

1 Answer 1

7

In fact i think you don't have a server.

So, you're getting your application through the file:// protocol.

But file:// protocol can't do http get methods for security reasons.

To solve your matter i suggest you to put your application on a simple web server (like Apache, or wamp, xamp, lamp etc) or better to use grunt to build your application and run it on a test server through node.js

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

1 Comment

good catch. this question has nothing to do with angular or json

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.