如何在couchDB中添加cors - 没有“Access-Control-Allow-Origin”标题存在于请求的资源中 [英] how to add cors in couchDB -- No 'Access-Control-Allow-Origin' header is present on the requested resource

查看:425
本文介绍了如何在couchDB中添加cors - 没有“Access-Control-Allow-Origin”标题存在于请求的资源中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个将pouchDb的数据同步到couchDb的html文件,但是iam在Chrome控制台中出现以下错误。

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.


未捕获TypeError:无法调用null的方法'addEventListener'

Uncaught TypeError: Cannot call method 'addEventListener' of null

OPTIONS < a href =http:// localhost:5984 / todos / =noreferrer> http:// localhost:5984 / todos / 405(方法不是
允许)

OPTIONS http://localhost:5984/todos/ 405 (Method Not Allowed)

选项 http:// localhost:5984 / todos / 否'访问权限-Control-Allow-Origin'标题出现在
所请求的资源上。因此,不允许访问Origin' http:// localhost:8080 '。
XMLHttpRequest无法加载 http:// localhost:5984 / todos / 。没有'Access-Control-Allow-Origin'
标头出现在请求的资源上。 Origin' http:// localhost:8080 '
因此不被允许访问。
选项 http:// localhost:5984 / todos / 否'访问控制 - 允许 - 来源'header
存在于请求的资源上。 Origin' http:// localhost:8080 '
因此不被允许访问。 pouchdb-nightly.js:3496
选项 http:// localhost:5984 / todos / 否' Access-Control-Allow-Origin'标头在请求的资源上出现
。 Origin' http:// localhost:8080 '
因此不被允许访问。 pouchdb-nightly.js:3496
XMLHttpRequest无法加载 http:// localhost:5984 / todos / 。请求的
资源上没有
'Access-Control-Allow-Origin'标头。原因' http:// localhost:8080 '因此不允许
访问。

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.But这没有解决问题。
我在这里看到很多类似的问题,但我不明白任何答案,因为我在这个领域比较新。

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支持,您需要设置 enable_cors = true 选项
in在 local.ini 中的 [httpd] 部分添加一个 [cors] code>部分
包含 origins = * 设置。请注意,默认情况下,没有来源接受
;你必须使用通配符或白名单。

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 = *


这篇关于如何在couchDB中添加cors - 没有“Access-Control-Allow-Origin”标题存在于请求的资源中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆