无法加载Firebase(重定向错误) [英] Failed to load firebase (redirected error)

查看:58
本文介绍了无法加载Firebase(重定向错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习Ajax,但我还不知道后端语言,所以我正在使用Google的Firebase,并且正在使用python 2.7通过localhost:8000运行代码.我正在尝试GET/POST到此服务器:

https://ajax-practice-1f1b9.firebaseio.com/

如果您无法访问它,则我的JSON如下所示:

[
    {
        "id": 1,
        "name" : "Will",
        "drink": "American with creme"
    },
    {
        "id": 2,
        "name": "Donat",
        "drink": "Vanilla Macchiato"
    }
]

这是我的HTML和javascript

 $(function() {
    $.ajax({
        type: 'GET',
        url: 'https://ajax-practice-1f1b9.firebaseio.com',
        success: function(data) {
            console.log(data);
        }
    });
}); 

 <!doctype HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>AJAX jQuery course</title>
        <!-- latest bootstrap css -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    </head>

    <body>

        <h1>JQuery Ajax Tutorial</h1>
        <h2>Coffee Order</h2>

        <ulid="orders"></ul>

        <p>name: <input type="text" id="name"></p>
        <p>drink: <input type="text" id="drink"></p>
        <button id="add-order">Add</button>

        <!-- <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase.js"></script> -->

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="index.js"></script>
    </body>
</html> 

我在控制台上收到此错误:

无法加载 https://console.firebase .google.com/project/ajax-practice-1f1b9/database/data/:从'"> https://accounts.google.com/ServiceLogin?passive=1209600&osid=1&继续= https://console.firebase.google.com/project/ajax-practice-1f1b9/database/data/& followup = https://console.firebase.google.com/project/ajax-practice-1f1b9/数据库/数据/"已被屏蔽CORS政策:所请求的资源上没有"Access-Control-Allow-Origin"标头.因此,不允许访问原始空".

不久前,我使用axios和ReactJs做过类似的事情,并且没有问题.

解决方案

URL https://ajax-practice-1f1b9.firebaseio.com将尝试在https://ajax-practice-1f1b9.firebaseio.com/

If you can't access it, my JSON looks like this:

[
    {
        "id": 1,
        "name" : "Will",
        "drink": "American with creme"
    },
    {
        "id": 2,
        "name": "Donat",
        "drink": "Vanilla Macchiato"
    }
]

here's my HTML and javascript

$(function() {
    $.ajax({
        type: 'GET',
        url: 'https://ajax-practice-1f1b9.firebaseio.com',
        success: function(data) {
            console.log(data);
        }
    });
});

<!doctype HTML>
<html>
    <head>
        <meta charset="utf-8">
        <title>AJAX jQuery course</title>
        <!-- latest bootstrap css -->
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
    </head>

    <body>

        <h1>JQuery Ajax Tutorial</h1>
        <h2>Coffee Order</h2>

        <ulid="orders"></ul>

        <p>name: <input type="text" id="name"></p>
        <p>drink: <input type="text" id="drink"></p>
        <button id="add-order">Add</button>

        <!-- <script src="https://www.gstatic.com/firebasejs/5.3.1/firebase.js"></script> -->

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="index.js"></script>
    </body>
</html>

I get this error on the console:

Failed to load https://console.firebase.google.com/project/ajax-practice-1f1b9/database/data/: Redirect from 'https://console.firebase.google.com/project/ajax-practice-1f1b9/database/data/' to 'https://accounts.google.com/ServiceLogin?passive=1209600&osid=1&continue=https://console.firebase.google.com/project/ajax-practice-1f1b9/database/data/&followup=https://console.firebase.google.com/project/ajax-practice-1f1b9/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.

I did something similar using axios and ReactJs a while back and it worked without problems.

解决方案

The URL https://ajax-practice-1f1b9.firebaseio.com will try to load the database in the Firebase Database console. You are probably trying to get the data through Firebase's REST API, which requires that the URL ends in .json.

So to get the JSON for that location, use https://ajax-practice-1f1b9.firebaseio.com/.json.

这篇关于无法加载Firebase(重定向错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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