1
這是使用Firebase的網絡應用程序html代碼。目標是實時檢索數量,而無需刷新/重新加載頁面。如何在不刷新Firebase的情況下實時更新網頁?
怎麼辦? Thxs。
<!DOCTYPE html>
<html lang="en">
<head><meta charset="utf-8"></head>
<body>
<span class="qty" id="qty">0</span>
<script src="https://www.gstatic.com/firebasejs/4.3.1/firebase.js"></script>
<script>
var config = { ... };
firebase.initializeApp(config);
</script>
<script>
var dbRef = firebase.database().ref();
var startListening = function() {
dbRef.on('child_added', function(snapshot) {
var warehouse = snapshot.child("prod_id/stats").val();
document.getElementById("qty").innerHTML = warehouse.qty
});
}
startListening();
</script>
</body>
</html>
的路徑爲 「PROD_ID /統計/數量」。工作正常。 – hbbz040
很高興幫助你。 – Ridwan