Replicate data from CouchDB to PouchDB for offline storage on windows 7 using google Chrome V22

StackOverflow https://stackoverflow.com/questions/12721950

سؤال

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