I want to present some data from Firebase to a webpage, and I´m following this Firecast totorial: Firebase tutorial
This is exactly what I need, but I can't get it to work. There is no data showing up. Here is the code:
(function() { // Initialize Firebase const config = { apiKey: "myKey", authDomain: "myApp.firebaseapp.com", databaseURL: "https://myApp.firebaseio.com", projectId: "myId", storageBucket: "myApp.appspot.com", messagingSenderId: "xxxxxxxxxx" }; firebase.initializeApp(config); //Get elements const preObject = document.getElementById('object'); //Create refrence const dbRefObject = firebase.database().ref().child('object'); //Sync object changes dbRefObject.on('value', snap => console.log(snap.val())); }());
<!DOCTYPE html <html> <head <meta charset="utf-8"> <title>Test</title> <script src="https://www.gstatic.com/firebasejs/live/3.1/firebase.js"></script> </head> <body> Test <!-- Value --> <pre id = "object"></pre> <!-- Child --> <script src ="App.js"></script> </body> </html>
to be able to read and write to your database you need to change database rules to be like this
{
"rules": {
".read": true ,
".write": true
}
}
of course that's, only in development..
here is jsfiddle so you can see results from my database
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.