我正在尝试创建一个html文件,该文件将数据从pouchDb同步到couchDb ..but iam,在chrome控制台中出现以下错误。
未捕获TypeError:无法调用null的方法“addEventListener”
选项http://localhost:5984/todos/ 405 (不允许使用方法)
OPTIONS http://localhost:5984/todos/否请求的资源上存在'Access-Control-Allow-Origin‘标头。因此不允许访问源'http://localhost:8080‘。XMLHttpRequest无法加载http://localhost:5984/todos/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问源'http://localhost:8080‘。OPTIONS http://localhost:5984/todos/否请求的资源上存在'Access-Control-Allow-Origin‘标头。因此不允许访问源'http://localhost:8080‘。pouchdb-nightly.js:3496 OPTIONS http://localhost:5984/todos/ No 'Access-Control-Allow-Origin‘标头出现在请求的资源上。因此不允许访问源'http://localhost:8080‘。http://localhost:5984/todos/ -nightly.js:3496 XMLHttpRequest无法加载pouchdb。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问源'http://localhost:8080‘。
我找到了一种方法来避免这个问题。也就是说,我必须使用以下命令打开chrome : cd:\Program Files (x86)\Google\Chrome\Application Chrome.exe --disable-web-Security.但是这并没有解决这个问题.我看到很多类似的问题here.but我不明白任何答案,因为我是这个领域的新手
发布于 2014-01-03 20:37:13
要启用CORS支持,您需要在
local.ini
的[httpd]
部分设置enable_cors = true
选项,并添加一个包含origins = *
设置的[cors]
部分。请注意,默认情况下,不接受任何来源;您必须使用通配符或白名单。
httpd enable_cors = true cors原点= *
发布于 2016-03-19 00:32:50
公认的答案并不能解决我的问题。我所做的是-
更新local.ini (/installation location/CouchDB/etc/couchdb)
[httpd]
enable_cors = true
[cors]
origins = *
credentials = true
methods = GET, PUT, POST, HEAD, DELETE
headers = accept, authorization, content-type, origin, referer, x-csrf-token
然后在管理员模式下打开CMD并运行-
net.exe stop "Apache CouchDB" && net.exe start "Apache CouchDB"
*仅供windows用户使用
发布于 2015-02-17 18:12:03
couchdb中的CORS部分:
credentials: true
headers: accept, authorization, content-type, origin, referer, cache-control, x-requested-with
methods: GET,PUT,POST,HEAD,DELETE
origins: *
请注意x-requested-with
https://stackoverflow.com/questions/20897033
复制相似问题