I am trying to replicate data from CouchDB to PouchDB for offline storage using the code to pull data from CouchDB:

db.replicate.from('http://test.iriscouch.com/todo','idb://todo', function (err, changes) {
if (err) {
    console.log(err);
}
else {
    console.log(changes);
}});
$scope.loadTodos(response.rows);

I get these errors:

  • Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
  • XMLHttpRequest cannot load http://test.iriscouch.com/todo/. Origin null is not allowed by Access-Control-Allow-Origin.
  • Uncaught TypeError: Cannot call method 'id' of undefined

Is there something I'm not doing correct?

有帮助吗?

解决方案

For PouchDB to communicate with CouchDB it either needs to be running on the same domain or you need to install a CORS-Proxy between Pouch and Couch, this is due to the same origin policy enforced by the browser, the next release of CouchDB will hopefully support this natively but in the meantime for a production site I would find it easiest to use nginx to have pouch and couch run off the same domain

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