未捕获的ReferenceError:未定义接收

时间:2018-09-01 17:32:04

标签: javascript html referenceerror

(现在已修复) (如果要使用此代码,请记住将其放在。之前和。之前。将body标记放在下面,因为必须将其放在代码的开头和结尾。 因此,我正在尝试实现一个函数,您可以在其中发布您的状态,而其他人则可以根据您在一开始就获得的google登录信息来查看其他人写的内容。我正在html文档中编写Javascript,并且旁边有一个CSS。我将Firebase托管,云和实时数据库与NODE.JS一起使用。我的很多代码都是基于下面这个绅士视频的: https://youtu.be/QuiZE5ZE4EE(Paul Baumgarten) 这是确切的错误:

Uncaught ReferenceError: receive is not defined
at receiveUpdate ((index):141)
at firebase-app.js:1677
at fc (firebase-app.js:1677)
at bf (firebase-app.js:1677)
at cf (firebase-app.js:1677)
at Object.G (firebase-app.js:1677)
at firebase-app.js:1677
at Ag.g.wd (firebase-app.js:1677)
at og.wd (firebase-app.js:1677)
at Yf.Xf (firebase-app.js:1677)

HTML:

var config = {
  apiKey: "AIzaSyC1ls01V0-7A1nCnZwfnuBsUwaboTUOE1E",
  authDomain: "ariadnes-string.firebaseapp.com",
  databaseURL: "https://ariadnes-string.firebaseio.com",
  projectId: "ariadnes-string",
  storageBucket: "ariadnes-string.appspot.com",
  messagingSenderId: "737704779364"
};
firebase.initializeApp(config);

function login() {
  function newLoginHappened(user) {
    if (user) {
      // User is signed in
      app(user);
    } else {
      var provider = new firebase.auth.GoogleAuthProvider();
      firebase.auth().signInWithRedirect(provider);
    }
  }

  firebase.auth().onAuthStateChanged(newLoginHappened)
}

function app(user) {
  // user.displayName
  // user.email
  // user.photoURL
  // user.uid

  function updateMyStatus(e) {
    var myUpdate = {};
    myUpdate.email = user.email;
    myUpdate.displayName = user.displayName;
    myUpdate.status = document.getElementById("clientStatus").value;
    fb.child("user.uid").set(myUpdate);
  }

  function receiveUpdate(received) {
    var data = received.val();
    console.log(data);
    document.getElementById("messages").innerHtml = "";
    for (var key in data) {
      var person = data[key];
      var p = "<p>" + person.displayName + " (" + person.email + ") said:" + person.status + "</p>";
      document.getElementById("messages").innerHTML += p;
    }
  }

  document.getElementById("clientName").innerHTML = user.displayName;
  document.getElementById("clientPhoto").setAttribute("src", user.photoURL)
  var fb = firebase.database().ref("whatsmystatus");
  document.getElementById("clientStatus").addEventListener("input", updateMyStatus);
  fb.on("value", receiveUpdate);
}
window.onload = login;
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>GSS</title>
  <link href="GSS_Home_Style.css" rel="stylesheet" type="text/css" />
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <link rel="icon" href="/favicon.ico" type="image/x-icon">
</head>
<header>
  <img src="logo.png" alt="logo" class="logo" />
  <input type="checkbox" id="nav-toggle" class="nav-toggle">
  <nav>
    <ul>
      <li><a href="GSS_Home_Html.html">Home</a></li>
      <li><a href="#">Forums</a></li>
      <li><a href="#">Settings</a></li>
      <li><a href="#">Support</a></li>
      <li><a href="GSS_Login_Html.html">Login</a></li>
    </ul>
  </nav>
  <label for="nav-toggle" class="nav-toggle-label">
            <span></span>
        </label>
</header>

<div class="loginbox">
  <img id="clientPhoto" src="" class="avatar">
  <h1>Hello <span id="clientName"></span></h1>
  <form>
    <div style="text-align: center">
      <div style="padding-bottom: 20px;">
        <p>What is your current status?</p>
        <div>
          <input type="text" id="clientStatus" maxlength="100" placeholder="Status...">
        </div>
        <p>Other people have left the following status messages:</p>
        <div id="messages"></div>

      </div>
    </div>
  </form>
</div>
<section id="hideonmobile2">
  <div class="loginboxright">
    <h1>Latest News</h1>
    <form>
      <div style="text-align: center">
        <div style="padding-bottom: 20px;">
          <p>Currently working on website - desktop program under construction</p>
          <p>Welcome to "Gamer's String". Our program is buildt to make an amazing community where you can post, view and complete tips and tricks. Get your post to the top by leveling up or purchasing our pro version. <strong>Good luck!</strong></p>
        </div>
      </div>
    </form>
  </div>
</section>


<section id="hideonmobile3">
  <footer>
    <div class="footer-social-icons">
      <ul class="social-icons">
        <li>
          <a href="
        https://www.facebook.com/ariadnes.string.9" class="social-icon">
            <i class="fa fa-facebook"></i></a>
        </li>
      </ul>
    </div>
  </footer>
</section>
<section id="showonmobile1">
  <footer>
    <div class="footer-social-icons">
      <ul class="social-icons">
        <li>
          <a href="https://www.facebook.com/ariadnes.string.9" class="social-icon"><i class="fa fa-facebook"></i></a>
        </li>
      </ul>
    </div>
  </footer>
  <script src="https://www.gstatic.com/firebasejs/3.8.0/firebase.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">
  </script>  <script src="#">  </script>

我确实有CSS,但是我决定对此没有关系
我将不胜感激任何帮助。

0 个答案:

没有答案