我正在尝试创建一个 html 文件,将数据从 pouchDb 同步到 couchDb ..但是我在 chrome 控制台中收到以下错误。
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.
我找到了避免这个问题的方法。那就是我必须使用以下命令打开 chrome:cd C:\Program Files (x86)\Google\Chrome\Application Chrome.exe --disable-web-security。但这并没有解决问题。 我在这里看到了很多类似的问题。但是我不明白任何答案,因为我在这个领域相对较新
最佳答案
来自 this documentation :
To enable CORS support, you need to set the
enable_cors = true
option in the[httpd]
section oflocal.ini
, and add a[cors]
section containing aorigins = *
setting. Note that by default, no origins are accepted; you must either use a wildcard or whitelist.[httpd] enable_cors = true [cors] origins = *
关于javascript - 如何在 couchDB 中添加 cors——请求的资源上不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897033/