最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firebase in Web : A network error (such as timeout, interrupted connection or unreachable host) has occurred? - Sta

programmeradmin4浏览0评论

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=".2.0/firebase.js"></script>
<script src=".2.0/firebase-app.js"></script>
<script src=".2.0/firebase-auth.js"></script>
<script src=".2.0/firebase-database.js"></script>
<script src=".2.0/firebase-messaging.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyDAvfWcdBTtmDbK7_aOkWFCRxNl1K4PDck",
    authDomain: "sarahhah-8e315.firebaseapp",
    databaseURL: "",
    projectId: "sarahhah-8e315",
    storageBucket: "sarahhah-8e315.appspot",
    messagingSenderId: "965679781332"
  };
  firebase.initializeApp(config);
  console.log(config);
</script>
<script type="text/javascript" src="assets/js/login.js"></script>

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./firebasejs/4.2.0/firebase.js"></script>
<script src="https://www.gstatic./firebasejs/4.2.0/firebase-app.js"></script>
<script src="https://www.gstatic./firebasejs/4.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic./firebasejs/4.2.0/firebase-database.js"></script>
<script src="https://www.gstatic./firebasejs/4.2.0/firebase-messaging.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyDAvfWcdBTtmDbK7_aOkWFCRxNl1K4PDck",
    authDomain: "sarahhah-8e315.firebaseapp.",
    databaseURL: "https://sarahhah-8e315.firebaseio.",
    projectId: "sarahhah-8e315",
    storageBucket: "sarahhah-8e315.appspot.",
    messagingSenderId: "965679781332"
  };
  firebase.initializeApp(config);
  console.log(config);
</script>
<script type="text/javascript" src="assets/js/login.js"></script>
copied the web code snipets ans pasted in the html code as attached and javascript code is also attached ! facing error as :

A network error (such as timeout, interrupted connection or unreachable host) has occurred. .

in web integration of firebase

thanks in advance for your cooperation

Share Improve this question edited Aug 18, 2017 at 8:04 KENdi 7,7792 gold badges18 silver badges31 bronze badges asked Aug 17, 2017 at 18:25 Rahul SharmaRahul Sharma 3583 silver badges10 bronze badges 5
  • This app is hosted on firebase-hosting ? you enable the Email/password sign-in method ? – aofdev Commented Aug 18, 2017 at 4:13
  • 2 Error resolved , used div tag instead of the form tag – Rahul Sharma Commented Aug 18, 2017 at 7:45
  • @RahulSharma OMG! Thank you! Why would placing the input fields in a "form" tag result in a network error in Firebase? Does the HTML markup have any influence on the request? Or on the Javascript function? Why? For everyone else: Remove your "form" tags around your "input" elements and it will work. – Zoltán Matók Commented Feb 21, 2018 at 20:30
  • I changed but again I am getting the same error – vijju Commented Mar 28, 2018 at 16:09
  • This is so weird, I do not have any form tag anywhere in my angular project. Even then I am getting the same issue. – Savaratkar Commented Jan 22, 2020 at 14:25
Add a ment  | 

1 Answer 1

Reset to default 7

I will duplicate an answer from ments from Rahul Sharma because this saved me a lot of time. Hope this will help somebody else:

Use <div> instead of <form> tag

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论