Web中的Firebase:发生了网络错误(例如超时,中断连接或无法访问的主机)?

时间:2017-08-17 18:25:37

标签: javascript firebase firebase-authentication

firebase.auth().onAuthStateChanged(function(user) {
  if (user) {
    // User is signed in.
      console.log("Hurray ! signed in successfully !");
  } else {
    // No user is signed in.
     console.log("Sign in required !");
     $("#login-btn-nav").click();
  }
});



$("#login-btn").on('click',function(){
    console.log("Hello");
    var email = $("#email-input").val();
    var password = $("#password-input").val();

    if(email != "" && password != ""){
    		firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) {
				  // Handle Errors here.
				  var errorCode = error.code;
				  var errorMessage = error.message;
				  // ...
				  window.alert("Following error encountered : "+errorMessage+" .");
				});
    		}
});
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-messaging.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyDAvfWcdBTtmDbK7_aOkWFCRxNl1K4PDck",
    authDomain: "sarahhah-8e315.firebaseapp.com",
    databaseURL: "https://sarahhah-8e315.firebaseio.com",
    projectId: "sarahhah-8e315",
    storageBucket: "sarahhah-8e315.appspot.com",
    messagingSenderId: "965679781332"
  };
  firebase.initializeApp(config);
  console.log(config);
</script>
<script type="text/javascript" src="assets/js/login.js"></script>
复制了链接在html代码中的web代码snipets和附加的javascript代码! 面临错误:

发生了网络错误(例如超时,中断连接或无法访问的主机)。

在firebase的web集成中

提前感谢您的合作

1 个答案:

答案 0 :(得分:4)

我将从Rahul Sharma的评论中复制答案,因为这为我节省了很多时间。希望这会帮助其他人:

用户<div>而不是<form>标签