I'm doing a web application with javascript, my js file has several CRUD functions, I wanted it when HTML was loaded, called two functions, so I added this code:
document.addEventListener('load', function() {
ler() //le os dados do firebase
mostrar() //mostra esse dados formatados
})
But it does not work, what's the problem?
Edit:
As you gave the hint, I used window
instead of document
and I put alert()
, for testing and it worked ( alert()
), so I guess something else is causing the problem
Here is the code for ler()
and mostrar()
:
function ler() {
json = []
firebaseRef.once("value")
.then(function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var key = childSnapshot.key
var obj = childSnapshot.val()
obj.key = key
json.push(obj)
})
})
}
function mostrar() {
receitas.innerHTML = ""
for(var i = 0; i < json.length; i++) {
receitas.innerHTML += '<div class="col s12 m4 l3">' +
'<div class="card">' +
'<div class="card-image">' +
'<img src="./image/default.png">' +
'<span class="card-title">' + json[i].nome + '</span>' +
'<span class="hide">' + json[i].key + '</span>' +
'</div>' +
'</div>' +
'</div>'
}
}
Both work by calling functions in the console