我已经设置了一个本地环境,其中我从JSON文件加载数据:

var Players = $resource('data/players.json');
var players = Players.query(function(){});
.

它很棒。 现在我想在不同的域名(http://playball.iriscouch.com/players)上访问couchdb,并根据Google Buzz exceme我尝试了以下情况,但我不能使它工作:

var Players = $resource('http://playball.iriscouch.com/players',  
  {alt: 'json', callback: 'JSON_CALLBACK'},
  {get:     {method: 'JSON'}
});

var players = Players.query(function(){});
.

我只是收到一个空数组......任何想法?

感谢BUCH!

SUE

有帮助吗?

解决方案

如果您有控制服务器,请使用 cors 要纠正您的示例:

var Players = $resource('http://playball.iriscouch.com/players',

  // These params will be set to each request (?alt=json&callback=JSON_CALLBACK),
  // where JSON_CALLBACK placeholder will be replaced with correct callback fn,
  // generated by Angular.
  {alt: 'json', callback: 'JSON_CALLBACK'},

  // You need to configure query method to use JSONP
  {query:     {method: 'JSONP'}
});

var players = Players.query(function(){});
.

一定要检查服务器是否响应正确的数据(Dev工具栏 - 网络面板)。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top