4

Using Angular 1.0.8 I was trying to load a JSON from a server that doesn't support get OPTIONS, and consequently got a error.

Demo for 1.0.8

OPTIONS http://www.json-generator.com/j/cdnueRTRmG 405 (Method Not Allowed)
OPTIONS http://www.json-generator.com/j/cdnueRTRmG Origin http://run.plnkr.co is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load http://www.json-generator.com/j/cdnueRTRmG. Origin http://run.plnkr.co is not allowed by Access-Control-Allow-Origin. 

I've tried to update angular to 1.2.0-RC and the error is gone.

Demo for 1.2.0

This is exactly the same code, a fork that loads the new version of angular, in fact the code is almost the same you can find in $http angularjs docs.

How can I fix the this problem using the v1.0.8?

I've read some hints about removing the headers from the request but couldn't make this work over the sample code above.

1 Answer 1

1

Try this:

delete $http.defaults.headers.common['X-Requested-With'];

I added that line before the call to $http and it worked in your 1.0.8 plunker.

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

3 Comments

The json-generator stuff backing that plunkr probably expired or was removed. The technique is still valid. Thanks for the downvote!
you should remove the plunkr link as it does not exist anymore.
@aet I'm having this same issue (client / api communication works when hosted on same server, but not cross domain) and this method causes a different error: Uncaught Error: [$injector:modulerr] errors.angularjs.org/1.3.2/$injector/……%20at%20Gd%20(http%3A%2F%2Flocalhost%3A5001%2Fjs%2Fangular.min.js%3A17%3A1)

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.