0

In my project I have one json files, One I deployed in the Local Machine/Server and other I deployed in the another server.

Here is my code for calling the json data from angular controller -

function Controller($scope, $http) {
    $http.get("http://localhost:8080/RESTCall/test.json").
        success(function(data) {
            $scope.lists= data;
        });
}


function Controller2($scope, $http) {
    $http.get("http://<Server IP>:8080/RESTCall/test.json").
        success(function(data) {
            $scope.lists= data;
        });
}

Here is my index.html page, where I am using both this controller :

    <div ng-controller="Controller">    
        <ul ng-repeat="list in lists">
            <li>            
            {{list.testdata}}
            </li>
        </ul>     
    </div>


    <div ng-controller="Controller2">    
        <ul ng-repeat="list in lists">
            <li>            
            {{list.testdata}}
            </li>
        </ul>     
    </div>

While executing I am getting the data which is coming from the Local Machine/Server OR but for Controller1 I am getting following Error :

OPTIONS http://<SERVER IP>:8080/RESTCall/test.json net::ERR_CONNECTION_REFUSED

When I am accessing direct http://<SERVER IP>:8080/RESTCall/test.json I am able to get the data..

6
  • Try it on a different browser. Commented Jan 5, 2016 at 7:04
  • @Goldenowner : I tried on Chrome and Firefox, Not working in both the cases.. Commented Jan 5, 2016 at 7:06
  • Have you already tried other things to fix it? For example clearing your cache data. There are many fixes for this problem on the internet. There is nothing wrong with your code, it's a client side error. Commented Jan 5, 2016 at 7:10
  • @Goldenowner : Yes.. I tried with cleaning the cache data also...but the json file which the controller1 is calling not loading.. Commented Jan 5, 2016 at 7:13
  • May I know your server side platform? Commented Jan 5, 2016 at 7:21

1 Answer 1

1

You are firing a cross-domain request (CORS). The browser will fire a pre-flight OPTIONS request first before firing the actual GET request. Therefore you will have to configure your server to response to OPTIONS request and return appropriate Access-Control-* headers.

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

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.