【发布时间】:2017-08-01 23:05:13
【问题描述】:
我正在尝试使用 $http 服务从我的 firebase 数据库中访问信息。这是我的代码:
$http.get("my firebase url").then(function(res) {
console.log(res);
});
但我得到一个 cors 错误:
XMLHttpRequest cannot load https://console.firebase.google.com/project/...
Redirect from 'https://console.firebase.google.com/project/...' to
'https://accounts.google.com/ServiceLogin?passive=44&osid=1&continue=ht…
owup=https://console.firebase.google.com/project/.../database/data/'
has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is
present on the requested resource. Origin 'null' is therefore not allowed access.
我尝试在谷歌上搜索该问题,但找不到任何我理解的内容。
注意:我是火力基地和有角的菜鸟。
【问题讨论】:
-
我会检查一下,但它似乎没有使用我想要使用的 angular $http 服务。
-
这是一个基于 HTTP 的通用“问题”。它确实与所有使用 HTTP 的技术相匹配。
-
从错误消息看来,您正在尝试从 Firebase 控制台读取数据。那是行不通的。如果要从数据库中读取数据,请确保
my firebase url的格式为https://yours.firebaseio.com/,您可以从 Firebase Database console 中复制该格式。 -
我有正确的 firebase url,我编辑了 url 和错误消息以隐藏敏感信息。
标签: javascript angularjs firebase-realtime-database xmlhttprequest