2016-11-17 59 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