ess*_*ess 19 javascript html5 couchdb cors pouchdb
我正在尝试创建一个html文件,它将数据从pouchDb同步到couchDb ..但是我在chrome控制台中遇到以下错误.
未捕获的TypeError:无法调用null的方法'addEventListener'
选项http:// localhost:5984/todos / 405(方法不允许)
选项http:// localhost:5984/todos /否请求资源上存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.XMLHttpRequest无法加载http:// localhost:5984/todos /.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.选项http:// localhost:5984/todos /否请求资源上存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.pouchdb-nightly.js:3496选项http:// localhost:5984/todos /否请求资源上存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.pouchdb-nightly.js:3496 XMLHttpRequest无法加载http:// localhost:5984/todos /.请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许来源" http:// localhost:8080 "访问.
我找到了避免这个问题的方法.这是我必须使用以下命令打开chrome:cd C:\ Program Files(x86)\ Google\Chrome\Application Chrome.exe --disable-web-security.But这并没有解决问题.我在这里看到了很多类似的问题.但我不明白任何答案,因为我在这个领域相对较新
rob*_*rtc 41
从这个文件:
要启用CORS支持,您需要
enable_cors = true在[httpd]部分中设置选项local.ini,并添加[cors]包含origins = *设置的部分.请注意,默认情况下,不接受任何来源; 你必须使用通配符或白名单.Run Code Online (Sandbox Code Playgroud)[httpd] enable_cors = true [cors] origins = *
接受的答案并不能解决我的问题.我做的是 -
更新local.ini(/安装位置/ 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
Run Code Online (Sandbox Code Playgroud)
然后以管理员模式打开CMD并运行 -
net.exe stop "Apache CouchDB" && net.exe start "Apache CouchDB"
Run Code Online (Sandbox Code Playgroud)
***仅适用于Windows用户
小智 5
可以通过http://localhost:5984/_utils(或者 CouchDB 运行的任何 URL,后跟 /_utils)访问 CouchDB UI 。在其中,您可以转到“配置”>“CORS”并启用或禁用 CORS。