最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to load a cross-domain JSON with $http in angularjs 1.0.8 as it does with 1.2.0 - Stack Overflow

programmeradmin2浏览0评论

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  405 (Method Not Allowed)
OPTIONS  Origin  is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load . Origin  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.

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./j/cdnueRTRmG 405 (Method Not Allowed)
OPTIONS http://www.json-generator./j/cdnueRTRmG Origin http://run.plnkr.co is not allowed by Access-Control-Allow-Origin.
XMLHttpRequest cannot load http://www.json-generator./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.

Share Improve this question asked Sep 19, 2013 at 22:24 a--ma--m 4,7821 gold badge41 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

Try this:

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

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

发布评论

评论列表(0)

  1. 暂无评论