2016-11-17 60 views
1

我正在按照Firebase在官方文檔中指定的電子郵件/密碼註冊設置進行操作;但是,在繼續進行身份驗證時,我仍然收到「發生網絡錯誤」錯誤。使用Firebase註冊電子郵件/密碼時發生「網絡錯誤」錯誤

驗證碼:

window.onload = function() { 
    const config = { 
     apiKey: "", 
    authDomain: "", 
    databaseURL: "", 
    storageBucket: "", 
    messagingSenderId: "" 
    }; 
    firebase.initializeApp(config); 
    const btnSignUp = document.getElementById('btnSignUp'); 

    btnSignUp.addEventListener('click', function() { 
    const inputEmail = document.getElementById('username-input'); 
    const inputPassword = document.getElementById('password-input'); 

    const email = inputEmail.value; 
    const password = inputPassword.value; 
    firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) { 
     console.log(error); 
    }); 
    }); 
}; 

控制檯錯誤:

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

請提供更多關於您正在使用的環境的信息。你還可以檢查你的網絡日誌嗎?請求是否已經發出?這應該有助於解釋事情。 – bojeil

回答

4

全部設置 - 在該按鈕的「型」屬性沒有被定義的問題,並默認爲一個提交類型。通過設置type =「button」,問題就解決了。

+1

我有同樣的問題,如何設置類型按鈕解決這個問題? – KaoriYui

+2

@KaoriYui如果按鈕的類型爲submit,並且它位於表單標籤內,它將觸發表單標籤中定義的動作,如果沒有任何動作,也會觸發刷新。發生這種情況時,Firebase的身份驗證請求會中斷並引發錯誤。通過將類型設置爲按鈕,這可以減輕發生的錯誤。 – Novo