首页 > 解决方案 > HTML 无法向 Firebase 发送数据

问题描述

在我写完之后firebase loginfirebase init这个文件这个文件出现了 My CSS firebaserc

{
  "projects": {
    "default": "smarthome-e154e"
  }
}

如果您想查看我的代码,请使用我的 HTML。

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Pembagi Kartu</title>
    <link rel = "icon" href = "title.png" type = "image/x-icon">
    <link rel="stylesheet" href="styles.css">
    <style>
        body {
          background-image: url('card2.jpg');
          background-repeat: no-repeat;
          background-attachment: fixed;
          background-size: cover;
        }
        </style>
  </head>
  <body>
    <header class="fixed-top bg-light">
        <nav class="navbar navbar-expand-lg navbar-light container">
            <a class="navbar-brand" href="#">Pembagi Kartu Otomatis</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
              <span class="navbar-toggler-icon"></span>
            </button>
          
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
              <ul class="navbar-nav ml-auto">
                <li class="nav-item active">
                  <a class="nav-link" href="index.html">Home <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                  <a class="nav-link" href="#">Pilihan</a>
                </li>
              </ul>
            </div>
          </nav>
    </header>
    <br><br><br><br><br>
    <content>
        <div class="container bg-light "style="min-height: 100%;height: 100%; background-color: aliceblue;">
            <div class="justify-content-center d-flex">
                <button type="button" class="btn btn-success" onclick="led1on()" id="Acak">Acak</button>
                <button type="button" class="btn btn-danger" onclick="led1off()" id="Tentukan">Tentukan</button>
                <button type="button" class="btn btn-primary">Mulai</button>
            </div>
            <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
        </div>
    </content>
    <br><br><br><br><br>
    <footer class="fixed-bottom bg-light">
        <br>
        <div class="inner container">
            <p>&copy; Renaldy Kevin Sidharta - 2021</p>
        </div>
    </footer>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="app.js"></script>
    </body>
</html>

我想将数据更新到 Firebase,我的项目是使用互联网打开或关闭灯。

我的 app.js

const firebaseConfig = {
SENSORED  };

  firebase.initializeApp(firebaseConfig);

  let database = firebase.database();

  function led1off(){
      console.log(document.getElementById());
    database.ref('Lampu/Led0').set("0");    
  }

  function led1on(){
    database.ref('Lampu/Led0').set("1");    
  }

写后我的错误firebase serve --debug --only function

[2021-11-09T12:17:35.704Z] AssertionError [ERR_ASSERTION]: expected value to be defined but got "undefined"
    at new AssertionError (internal/assert/assertion_error.js:467:5)
    at Object.assertDefined (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\utils.js:360:15)
    at C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\serve\index.js:15:36
    at arrayMap (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\lodash\lodash.js:653:23)
    at Function.map (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\node_modules\lodash\lodash.js:9622:14)
    at serve (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\serve\index.js:14:25)
    at Command.actionFn (C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\commands\serve.js:47:16)
    at C:\Users\Kevin\AppData\Roaming\npm\node_modules\firebase-tools\lib\command.js:190:25
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Error: An unexpected error has occurred.

发生什么事?我不知道如何解决这个问题。请帮我

我想将此数据库值更新为 0 或 1

在此处输入图像描述

注意:我正在使用 node.js

标签: javascripthtmlfirebase-realtime-databasefirebase-tools

解决方案


推荐阅读