Pregunta

He establecido un entorno local, donde cargué datos de un archivo JSON:

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

y funciona muy bien.

Ahora quiero acceder a un CouchDB en un dominio diferente (http://playball.iriscouch.com/players), y en función del ejemplo de Google Buzz, he intentado lo siguiente, pero no puedo hacerlo funcionar.:

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

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

Simplemente recibo una matriz vacía ... ¿Alguna idea?

¡Gracias un buch!

SUNE

¿Fue útil?

Solución

Si tiene control sobre el servidor, use cors .

Para corregir su ejemplo:

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(){});

Asegúrese de verificar si el servidor está respondiendo datos correctos (barra de herramientas DEV - Panel de red).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top