javascript - 如何在 couchDB 中添加 cors——请求的资源上不存在 'Access-Control-Allow-Origin' header

标签 javascript html cors couchdb pouchdb

我正在尝试创建一个 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 of local.ini, and add a [cors] section containing a origins = * 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/

相关文章:

javascript - CORS 在 http 服务器上失败

javascript - 将文件上传到 Amazon s3 - 客户端 javascript

javascript - Raphael js 无法在 ie8 上正确渲染复杂的 svg 路径

javascript - 我如何从这些数据中获取对象数组以获取状态并在 reactjs 中计数

javascript - 从 javascript 更新 google 联系人时出现问题

html - 我如何通过 svn 提供 html? (svn 可以充当网络服务器吗?)

javascript - 是否可以覆盖某些 Javascript 命令?

php - php登录后jquery重定向

html - 基于百分比的列/行跨度

reactjs - Cors TypeScript 中没有重载匹配此调用