繁体   English   中英

带有Firebase的Angular $ http.get

[英]Angular $http.get with firebase

我正在尝试使用$ http服务从我的Firebase数据库访问信息。 这是我的代码:

$http.get("my firebase url").then(function(res) {
    console.log(res);
});

但是我收到了错误提示:

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.  

我已尝试使用Google搜索该问题,但找不到我理解的任何内容。

注意:我是一个火力发烧友和有角度的菜鸟。

我希望这有帮助。

您将需要考虑以下三件事:
1.在URL上,使用FB域而不是控制台“ Ex: https : //YOUR_DOMAIN.firebaseio.com/ ..”
2.在结束时,你将需要扩展的URL以.json“例如:../settings/app 以.json”
3.并且您将需要添加相应的规则以允许访问:
例如:

{
    "rules": {
        ".read": "auth != null",
        ".write": "auth != null",
        "settings": {
            "app": {
                ".read": true,
                ".write": false
            }
        }
    }
}

然后,您可以使用$ http,如我的示例所示:

$http.get("https://YOUR_DOMAIN.firebaseio.com/settings/app.json")

在此处输入图片说明

这里的例子: https : //jsfiddle.net/moplin/1124204w/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM