当我单击cadastro.html上的exec cadastrarAluno()时,它将显示在控制台上:
加载资源失败:服务器响应状态为404()
cadastro.html:30未捕获的ReferenceError:在HTMLAnchorElement.onclick(cadastro.html:30)上未定义cadastrarAluno
如果我在没有Firebase托管的情况下在localhost上打开相同的文件,则xD看起来一切都很好我应该怎么做才能解决此问题?
function armazenaAluno(matricula, nome, turma, senha, nota = 'Nao realizado ainda') {
await firebase.database().ref('alunos/' + turma + '/' + matricula).set({
nome,
turma,
senha,
nota,
});
}
function validaCadastro(inputArray) {
for (let input of inputArray) {
if (input.value.length == 0) {
alert('ERRO: Preencha todos os campos')
return false
}
}
if (inputArray[3].value != inputArray[4].value) {
alert('ERRO: As senhas devem coincidir')
return false
}
return true
}
async function cadastrarAluno() {
let inputEls = document.getElementsByTagName('input')
if (validaCadastro(inputEls)) {
const matricula = inputEls[0]
const nome = inputEls[1]
const turma = inputEls[2]
const senha = inputEls[3]
await armazenaAluno(matricula, nome, turma, senha)
window.open('https://herancasexual.firebaseapp.com/')
}
}
<body>
<div id="message">
<h2>Olá, aluno(a)</h2>
<p id='cadastro'>Ainda não possui uma conta? <a href="./cadastro/cadastro.html" id='cadastre-se'>Cadastre-se</a></p>
</div>
<script src="https://www.gstatic.com/firebasejs/6.4.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/6.4.2/firebase-database.js"></script>
<script>
var firebaseConfig = 'secret '
firebase.initializeApp(firebaseConfig);
</script>
<script src="src/functions.js"></script>
</body>
</html>
<!-- begin snippet: js hide: false console: true babel: false -->
答案 0 :(得分:-1)
这取决于为您的应用程序提供服务的内容。如果仅运行.html文件。尝试将代码修改为相对路径。如果您正在运行服务器,请尝试在src中给出绝对路径。例如:
相对而言
<script src="../src/functions.js" type="text/javascript">
绝对是
<script src="{Root_path}/src/functions.js" type="text/javascript">
,根据您的服务器路径,根目录路径可以是localhost/bio2
文件夹。