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

javascript - Access Denied with $http request in Angular and IE8 - Stack Overflow

programmeradmin5浏览0评论

I am trying to get my angular app to do an $http.get request. Works everywhere but IE8. I am using latest Angular (1.0.6 I think). The only message IE gives is:TypeError:

Access is denied. undefined (in previous angular this was )

My host (nodejs)is set to send cors headers:

res.header('Access-Control-Allow-Origin', '*'); //config.allowedDomains
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Requested-By');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');

I have tried to get more info about the error using debug tools but:

Fiddler: doesn't show xmlhttprequests - seems you can hack your NET app to fix that but not sure what to do with my web page. DebugBar: doesn't show these requests either FirebugLite: 2 version I tried are broken - just random errors and doesn't load

Changing the hosts to same origin clears the issue so I assume it's trying something but man it's hard to debug.

Angular posts on this seem outdated and I am not sure what to do from here.

I am trying to get my angular app to do an $http.get request. Works everywhere but IE8. I am using latest Angular (1.0.6 I think). The only message IE gives is:TypeError:

Access is denied. undefined (in previous angular this was )

My host (nodejs)is set to send cors headers:

res.header('Access-Control-Allow-Origin', '*'); //config.allowedDomains
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, X-Requested-By');
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');

I have tried to get more info about the error using debug tools but:

Fiddler: doesn't show xmlhttprequests - seems you can hack your NET app to fix that but not sure what to do with my web page. DebugBar: doesn't show these requests either FirebugLite: 2 version I tried are broken - just random errors and doesn't load

Changing the hosts to same origin clears the issue so I assume it's trying something but man it's hard to debug.

Angular posts on this seem outdated and I am not sure what to do from here.

Share Improve this question asked Apr 11, 2013 at 23:08 cyberwombatcyberwombat 40.1k41 gold badges184 silver badges267 bronze badges 7
  • 1 Fiddler totally does show XHR for IE. If it didn't, that would be a HUGE oversight. stackoverflow./questions/7351238/… – Alan Commented Apr 11, 2013 at 23:16
  • Also to be accurate, IE8 and IE9 don't have XHR, but instead do XDomainRequest, or XDR. – Alan Commented Apr 11, 2013 at 23:18
  • Well I have read that fiddler post and check setting and for the life of me I cannot see any of these requests. Other posts indicate a proxy has to be set for fiddler to pick these up. And I am aware of the IE8 XHR - XDomainRequest - I just can't seem to fund current Angular docs on this. Some older posts indicate there is no support for XDomainRequests but not sure what current status is - I find it hard to believe that IE8 will not work with Angular $http – cyberwombat Commented Apr 11, 2013 at 23:24
  • it's very possible that my setup is what is making Fiddler not work - vmware client to an OSX Nodejs server. Nevertheless the main issue is simply getting IE8 to work – cyberwombat Commented Apr 11, 2013 at 23:25
  • Thats how my system is setup (granted I dont test IE8). I do know that $http should work with IE8, so there is likely some other issue. – Alan Commented Apr 12, 2013 at 0:00
 |  Show 2 more ments

3 Answers 3

Reset to default 7

This has nothing to do with $http. $http lets you make XHR(XDR) or JSONP requests. It doesn't provide a mechanism to circumvent the browsers same origin policy.

Changing the hosts to same origin clears the issue so I assume it's trying something but man it's hard to debug.

That's the key to your problem. IE8 doesn't support Cross-Origin-Resource-Sharing (CORS) very well. In order to make cross domain calls with IE8, you better off either:

  1. Use your nodejs app to proxy the request for you, letting you use the same domain.
  2. Use JSONP in your $http.get() request

There are a number of gotchas associated with CORS and IE8, which are outlined here.

I was running into this same issue, and while it's likely not ideal, one solution is to change IE's 'Access data sources across domains' security setting to Enable or Prompt:

http://technet.microsoft./en-us/library/dd346862.aspx

In my case I was running into the same thing when trying to fetch data (via angular's $resource) from my own API that was hosted on another domain. In IE8 & IE9 these requests would fail with the error you described above. Changing the security setting in IE to allow cross-domain data requests resolved that problem.

AngularJS doesn't support IE<=9 CORS.

As required, there is a link to github official AngualrJS website :

AngularJS Github official discussion

发布评论

评论列表(0)

  1. 暂无评论