从web客户端服务器运行firebase javascript

从web客户端服务器运行firebase javascript,javascript,html,firebase,Javascript,Html,Firebase,因此,我对Javascript没有太多的经验,在运行代码时遇到了麻烦。我已经开发了Android java方面的东西,但是当我尝试运行html文件时,什么都没有发生。我不确定我的代码是否有bug,或者我是否只需要“激活它”。这是我的html文件: <!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.firebase.com/js/client/2.4.1/fireb

因此,我对Javascript没有太多的经验,在运行代码时遇到了麻烦。我已经开发了Android java方面的东西,但是当我尝试运行html文件时,什么都没有发生。我不确定我的代码是否有bug,或者我是否只需要“激活它”。这是我的html文件:

<!DOCTYPE html>
<html lang="en">
  <head>
    <script src="https://cdn.firebase.com/js/client/2.4.1/firebase.js">
    var Firebase = require("firebase");

    var ref = new Firebase("gd-prototype.firebaseio.com");
    var weight = new Firebase("gd-prototype.firebaseio.com/weights");
    ref.authWithCustomToken("AUTH_TOKEN", function(error, authData) {
        if (error) {
            console.log("Authentication Failed!", error);
        } else {
          console.log("Authenticated successfully with payload:", authData);
        }
    });

    weight.on("child_added", function(snapshot, prevChildKey) {
        var currentWeights = snapshot.val();
        var currentWeight1 = currentWeights.w1;
        var currentWeight2 = currentWeights.w2;
        var currentWeight3 = currentWeights.w3;
    });

    var users = new Firebase("server.firebaseio.com/users");
    ref.on("child_added", function(snapshot, prevChildKey) {
        var gradient = snapshot.val();
        var g1 = gradient.g1;
        var g2 = gradient.g2;
        var g3 = gradient.g3;
        var weight1 = currentWeight1 - g1;
        var weight2 = currentWeight1 - g2;
        var weight3 = currentWeight1 - g3;

        weights.set({
            w1: weight1,
            w2: weight2,
            w3, weight3
            });
    });

    users.on("child_changed", function(snapshot) {
        var gradient = snapshot.val();
        var g1 = gradient.g1;
        var g2 = gradient.g2;
        var g3 = gradient.g3;

        var weight1 = currentWeight1 - g1;
        var weight2 = currentWeight1 - g2;
        var weight3 = currentWeight1 - g3;

        weights.set({
            w1: weight1,
            w2: weight2,
            w3, weight3
            });
    });

    </script>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <title></title>
  </head>
  <body>
    Gradient Descent Server
  </body>
</html>

您从未定义过
weights
变量,因此
weights.set
相当于
未定义。set

堆栈溢出不能替代调试器。加载此页面时,您是否在JavaScript控制台中看到任何错误?
"server": {
  "users":{
    "uid1":{
      "g1": "1.0",
      "g2": "2.5",
      "g3": "1.0",
     }
     "uid2":{
      "g1": "1.1",
      "g2": "0.5",
      "g3": "3.0",
      }
    }
   "weights":{
     "w1": 0,
     "w2": 0,
     "w3": 0}
 }