Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am new in AngularJS. I have a situation where I need to call and read a json file. Here is my Code

 <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    </head>
    <body>
    <div ng-app="myApp" ng-controller="myCtrl">
    <ul>
        <li ng-repeat="todo in todos">
        {{todo.text}} - <em>{{todo.done}}</em>
        </li>
    </ul>
    </div>
    <script>
    var app = angular.module("myApp", []);
    app.controller("myCtrl", function($scope, $http) {
        $http.get('todos.json').success (function(data){
            $scope.todos = data;
        });
    });
    </script>
    </body>
    </html> 

This code runs fine in firefox but not in Chrome. please help me..

share|improve this question
    
Is there any failure message? What exactly does not work? –  Patrick Aug 29 '14 at 9:23
    
no error message is coming. but when i go to console then there was a error message- XMLHttpRequest cannot load file:///C:/Users/USER/Desktop/todos.json. Received an invalid response. Origin 'null' is therefore not allowed access. –  Subho Aug 29 '14 at 9:32
3  
@Subho it seems that you need to use a webserver, Chrome doesn't allow request from local or file://resources. See stackoverflow.com/questions/4208530/… –  khakiout Aug 29 '14 at 9:45
1  
Can you try to open your file via web Server. Chrome does not allow AJAX requests for file:/// URLs. Try to open it like http://localhost/PathToYourFile. You need to copy your file into your app to get it via WebServer. –  Patrick Aug 29 '14 at 9:46
    
yup.. when i try to run this code from Netbeans or Eclipse, its working. Do i need to change anything in my code?? Thank you all for your cooperation. –  Subho Aug 29 '14 at 9:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.