简体   繁体   中英

How to use the Firebase real time database for web application

In my website I'm Showing my database after user has given the database name, Is there any way I can constantly update the web shown databasebase without refreshing the page . I've tried using setInterval but it's not working for some reason .

function c(){

setInterval(beta, 1000); }

function beta(){

var d = document.getElementById("opopo").value;

var firebaseRefff= firebase.database().ref('LOCATION/'+d);

firebaseRefff.on('child_added', snap=> {

var slot=snap.getKey();

var alloted=snap.child("ALLOTED").val();

var date=snap.child("DATE").val();

var limit=snap.child("LIMIT").val();

var time=snap.child("TIME").val();

$("table tbody").append(""+slot+""+alloted+""+date+""+limit+""+time+"Null"); });

}

You do not need, and should not use, setInterval to trigger the queries. What you have in your beta() function looks pretty good.

firebaseRefff.on('child_added', snap => {}) means "whenever a child is added under this location, trigger the callback function (empty in my example) with the parameter 'snap'". It will also be called once, initially, for each child that is already at that database reference location.

You need to make sure you've called beta() once to setup this trigger.

If you're still having problems, you might want to insert logging to make sure beta() is being called, what the full reference path is, if the callback is ever triggered, and if your jquery string is correct.

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.

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