How to configure Angular $resource (ngResource) to pull data from another domain using CORS

你。 提交于 2019-12-03 14:09:24

OK, the solution I've found for my project is xdomain: https://github.com/jpillora/xdomain

I accept that this may not be suitable for everyone but it's a decent cross browser solution and whilst we're stuck with IE<10 this seems to be the best solution. (I am aware IE8 and IE9 provide partial support but that as always with IE isn't full support and I don't want to have to waste time doing another work around for IE).

Thanks to everyone who provided answers to the question.

I think this sample could work for you

angular.module('myBeerApp.services', ['ngResource']).
  value('version', '0.1').
  factory('beerDB', function($resource) {
    return $resource('URL',{
      alt:'json',
      appToken:'TOKEN',
      q:'rock',
      callback: 'JSON_CALLBACK'
    },
      {
        get: {
          method:'JSONP',
          headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
            }
          }
      });
  });

Are you calling useXDomain = true in your app.config();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!