I am trying to create a html file which synchronize data from a pouchDb to couchDb ..but iam getting the following error in chrome console.
Uncaught TypeError: Cannot call method 'addEventListener' of null
OPTIONS http://localhost:5984/todos/ 405 (Method Not Allowed)
OPTIONS http://localhost:5984/todos/ No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. XMLHttpRequest cannot load http://localhost:5984/todos/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. OPTIONS http://localhost:5984/todos/ No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. pouchdb-nightly.js:3496 OPTIONS http://localhost:5984/todos/ No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. pouchdb-nightly.js:3496 XMLHttpRequest cannot load http://localhost:5984/todos/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
I found a way to avoid this issue. That is i have to open chrome using the below command: cd C:\Program Files (x86)\Google\Chrome\Application Chrome.exe --disable-web-security.But this didn't solve the issue. I saw a lot of similar question here.but i didn't understand any answer since i am relatively new in this field
CORS section in couchdb:
Notice
x-requested-with
Accepted answer doesn't solve my problem. What i did is -
update local.ini (/installation location/CouchDB/etc/couchdb)
Then open CMD in administrator mode and run -
*** for windows user only
From this documentation:
Per @szydan comment, in case your package manager still serves you 1.2 version, which doesn't support CORS OPTIONS, you need to install it from source.
You may need to install SpiderMonkey and jsapi dependencies
Easiest way i found is to install the following:
Then run the tool i.e. "add-cors-to-couchdb" from the command line like this:
Check out the following link for CouchDB how to CORS reference
For windows users , go into apache install folder(C:\Program Files (x86)\Apache Software Foundation\CouchDB\etc\couchdb) <-- was here for me , and update the local.ini file with the below details ...worked a charm for me , thanks guys
obviously , restart the apache couchdb service for completeness :)