简体   繁体   English

将数据从Firebase显示到HTML网页上

[英]Displaying data from Firebase onto HTML Webpage

I am able to pull data from firebase and show it in the browser console, but how do I actually display it as text on a webpage? 我可以从firebase中提取数据并在浏览器控制台中显示它们,但实际上如何将其显示为网页上的文本?

Here's the code I have now: 这是我现在拥有的代码:

 <script> var ref = new Firebase("https://datatest-104.firebaseio.com"); ref.orderByChild("location").equalTo("United States").on("child_added", function(snapshot) { console.log(snapshot.key()); }); //My code that I'm trying: document.write(snapshot.key()); </script> 

I am trying to use document.write(snapshot.key()); 我正在尝试使用document.write(snapshot.key()); but am not sure how it works. 但不确定如何运作。

Put document.write(snapshot.key()); document.write(snapshot.key()); into the function instead of out of it: 进入功能而不是脱离功能:

 ref.orderByChild("location").equalTo("United States").on("child_added", function(snapshot) { document.write(snapshot.key()); }); 

Then, the snapshot will be defined, so it'll write onto the page. 然后,将定义snapshot ,以便将其写入页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM