6

I am new to angularjs and i am doing simple study on angular controllers and models. this is my javascript model code.

    var testApp = angular.module('testApp', []);

testApp.controller('testCtrl', function testCtrl($scope ,$http) {

  $http.get('test.json').success(function ($data){

   $scope.artists = $data;

  });

});

The webpage is loaded but comes an exception. I am using firefox in Windows 7.

[Exception... "Access to restricted URI denied" code: "1012" nsresult: "0x805303f4 >.>(NS_ERROR_DOM_BAD_URI)" location: "file:///....// angular.min.js Line: 72"]

Does anybody knows a solution.. I dont need to make it in a server only need to use local machine..

6
  • stackoverflow.com/questions/19116070/… Commented Aug 18, 2014 at 10:03
  • you need to have the json file hosted in a server. loading it from a file is restricted due to security. Commented Aug 18, 2014 at 10:04
  • I think the fire fox security causes for this. I think you are an student and what is your purpose of doing this in locally. check another browser. Commented Aug 18, 2014 at 10:05
  • Donal thank you but how can I fix it.. Commented Aug 18, 2014 at 10:07
  • chiran that is only for education but if it can fix that is good. Commented Aug 18, 2014 at 10:10

3 Answers 3

1

You have to do a minor correction to the angular controller syntax.

testApp = angular.module('testApp', []);
testApp.controller('testCtrl', function($scope, $http) {
    $http.get('test.json').success(function($data) {
       $scope.artists = $data;
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

while defining a controller, dont want to give the controller name next to function. SO just I removed it.
So, this is not an answer to the question. BTW, the controller name might be useful when debugging.
Actually the problem is not about the code i think. That is because of the browser effect i think.. but thank you any way..
1

As was already mentioned in the comments above, this is likely due to Firefox's security preventing your code from gaining acces to files in your local file system.

You can configure Firefox to access local content by changing your browser's config.

In Firefox:

  • Go to about:config
  • Find security.fileuri.strict_origin_policy parameter
  • Set it to false

Comments

0

Check it once in chrome by disabling web securities and if the same error occur then there might be a problem in the url of json file.

Go through How can I load a local json file?

You may find what the problem is.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.