0

I have a lightweight Angularjs app and I'm trying to process json from my ASP.NET Web Api controller.

In the angularjs factory:

adapter.getLegacyCouriers = function(id) {
  return $http({
    method: 'GET', 
    url: 'http://legacywebapi.azurewebsites.net/api/legacycourier'
  });
}

In the controller:

legacyService.getLegacyCouriers()
.success(function (response) {
       alert("Success: " + JSON.stringify(response));
})
.error(function (response) { 
    alert("Error: " + JSON.stringify(response)); 
});

When I exchange the URL in the $http get with this one it hits the success block. However, my default URL which returns json formatted in the same way hits the error block.

Can someone help me? Both returns application/json response headers, and both return a status of 200 OK (using Chrome to debug). I can't figure out why my json is hitting the error block.

7
  • @mmeverdies this message correspond as the example of success request Commented Sep 5, 2014 at 21:03
  • @rnrneverdies I wasn't getting that "daily limit" message when I was testing the geonames api. It was returning an actual json result set that was formatted the exact (or so I believe) same way as my one returned from the Web Api controller. Commented Sep 5, 2014 at 21:05
  • Looks like a paremeter issue. Probly the method has no default parameters. Something is happening in the server side. Try to log any exception in the api Commented Sep 5, 2014 at 21:05
  • @Fals There is no server side error as you can see by testing the URL: legacywebapi.azurewebsites.net/api/legacycourier - it responds with a 200 OK and the application/json header Commented Sep 5, 2014 at 21:06
  • 1
    I've got response No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'run.jsbin.com' is therefore not allowed access. from your legacywebapi.azurewebsites.net/api/legacycourier please see here jsbin.com/nugif/1/edit Commented Sep 5, 2014 at 21:25

1 Answer 1

2

Your service responing with

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'run.jsbin.com'; is therefore not allowed access. from your legacywebapi.azurewebsites.net/api/legacycourier

please see here jsbin.com/nugif/1/edit.

Just enable cross-origin resource sharing.

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

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.