简体   繁体   中英

Chrome / IE, AngularJS, and Access-Control-Allow-Origin

I'm building a web app in AngularJS that's supposed to be distributable via CDs, but I've hit a brick wall with the same origin policy of Chrome and IE, respectively:

XMLHttpRequest cannot load file:///xxx. Origin null is not allowed by Access-Control-Allow-Origin. 

Is there any way I can bypass this in code or by some other means?

The solution I went with is to define all templates inline in the index.html file via the <script type="text/ng-template"> directive like this:

<script type="text/ng-template" id="/template.html">
     <h1>I'm the content</h1>
</script>
<ng-include src="/template.html"></ng-include>

yes you can by
delete $http.defaults.headers.common['X-Requested-With'];

before the request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM