为什么我在读取一次值后获得的承诺永远不会得到解决?

时间:2017-05-23 14:47:03

标签: javascript jquery firebase firebase-realtime-database

我想知道为什么读取一次值后得到的承诺永远不会得到解决。我知道这是因为then()方法永远不会被执行。程序来自“按下发布按钮”。 “我出去了!”。

$(document).ready(function() {
  $("#header").load("header_organization.html", function(){

    console.log("Header loaded.");

    // Set up UI elements
    var publish_button = document.querySelector("#publish_button"),
        logout_button = document.querySelector("#logout_button"),
        title = document.querySelector("#title"),
        date = document.querySelector("#date"),
        hour = document.querySelector("#hour"),
        place = document.querySelector("#place"),
        brief_description = document.querySelector("#brief_description"),
        detailed_description = document.querySelector("#detailed_description"),
        contact_email = document.querySelector("#contact_email"),
        contact_phone_number = document.querySelector("#contact_phone_number"),
        image_input = document.querySelector("#imageUrl");
    console.log("Inputs referenced.");

    //Logout 
    logout_button.addEventListener('click', function(e){
      firebase.auth().signOut();
      console.log("You have been logged out");
      window.location = "index.html";
    });

    //Initialize Firebase
    var auth = firebase.auth(),
        storage = firebase.storage(),
        database = firebase.database();

    console.log("Firebase inizialized.");

    //Publish event
    publish_button.addEventListener('click', function(e){
      console.log("Publish button have been pressed.");
      //Read a value of one of the user's attributes
      database.ref("users/"+auth.currentUser.uid).once('value')
      .then(function(snapshot){
        console.log("Never reach this point");
      });
      console.log("I am out!");
    });
  });
});

0 个答案:

没有答案