0

I have access to some database on other server but still I am not being able to get data for this json it shows cors and shows 2 errors XHR failed loading: GET, XMLHttpRequest cannot load:CORS but I do have access to that server earlier also it showed cors while posting data but there was some code error and not server acceptance problem. This time in getting data is also I guess some code error on my side

{
  "emp": [
    {
      "BNK": "Rock",
      "GPIs": [
        "9233333456"
      ]
    },
    {
      "BNK": "Jack",
      "GPIs": [
        "9234343434",
        "9289989898"
        ]
    }
  ],
"status": "ok"
}



 <script>
  var countryApp = angular.module('countryApp', []);
  countryApp.controller('CountryCtrl', function ($scope, $http){
    $http.get('http://oher_server_url').success(function(data) {
      console.log(data);
      $scope.dta = data.emp;
    });
  });
</script>

  <table border=1>
                <tr>
                <th>type_BNK</th>
                <th>type_GPIs</th>
                </tr>
                <tr ng-repeat="x in dta ">
                <td>{{x.BNK}}</td>
                <td>{{x.GPIs}} </td>
  </table>
2
  • the url you're trying to access is is a different domain that yours and hence being rejected. You'll need to configure the server to allow your domain. Commented Feb 29, 2016 at 7:44
  • My domain is allowed on that server Commented Feb 29, 2016 at 7:45

2 Answers 2

2

It seems like you didn't enabled cross origin resource sharing on the server so your web page can't access the server, it's a little hard to know for sure if the problem is in the server or at your web page.

you need to check if you have Access-Control-Allow-Origin in your headers, if you don't, you should enable it, I don't know what technology the server is using but there are lots of guide for difference technologies here.

If the header did exist and accepted your domain it's probably because your browser doesn't support CORS, you can check if the browser you are using at caniuse.

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

1 Comment

CORS is enabled on server and Browser also supports CORS
0

The similler problem listed here,

Cross domain XHR failing

if you are loading json data, recommend to use $http.jsonp

You may also consider writing http interceptor like this

XHR Interceptor in an AngularJS web app

Comments

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.