未捕获的ReferenceError:未定义Firebase

Edd*_*dev 19 javascript firebase firebase-realtime-database

我正在尝试按照关于在firebase中设计数据库的教程,但我在JavaScript控制台中收到以下错误:

未捕获的ReferenceError:未定义Firebase

这是教程的链接,我试图在JavaScript控制台中运行的代码片段是:https://www.firebase.com/blog/2014-11-04-firebase-realtime-queries.html

var ref = new Firebase("https://dinosaur-facts.firebaseio.com/dinosaurs");
ref.orderByChild("height").on("child_added", function(snapshot) {
  console.log(snapshot.key() + " was " + snapshot.val().height + " meters tall");
});
Run Code Online (Sandbox Code Playgroud)

guy*_*abi 18

有关如何迁移到新版本的指南.
您可以在以下网址找到它:https://firebase.google.com/support/guides/firebase-web

这是相关的代码片段

在此输入图像描述

  • 当我添加此代码时,我收到“ReferenceError: firebase is not defined”。你从哪里得到“firebase”变量? (4认同)

Edd*_*dev 10

在标题中,包括以下内容:

<head>
    <script src='https://cdn.firebase.com/js/client/2.2.1/firebase.js'></script>
    <script src='https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js'></script>
    <link rel='stylesheet' type='text/css' href='/resources/tutorial/css/example.css'>
  </head>
Run Code Online (Sandbox Code Playgroud)

这将解决问题.

  • 这是新脚本`&lt;script src="https://www.gstatic.com/firebasejs/4.3.0/firebase.js"&gt;&lt;/script&gt;` (2认同)