我是否需要在项目的所有javascript文件中添加firebase Web API代码?当我在第一页上使用它时,它正在工作。现在我把它放在第二页,firebase代码无法正常工作。
这是索引页面代码,它正在运行。
var config = {
apiKey: "AIzaSyAPlhWdY7OVAEI_LrGMP073D5Ra6g",
authDomain: "mgf.firebaseapp.com",
databaseURL: "https://mgf.firebaseio.com",
projectId: "mgf",
storageBucket: "mgf.appspot.com",
messagingSenderId: "579064514788"
};
firebase.initializeApp(config);
function login()
{var pass;
var database = firebase.database();
var dbref=database.ref();
dbref.child('Admin').child('AdminName').once('value', snap=>
{
if(document.getElementById('txtan').value==snap.val()){
dbref.child('Admin').child('password').once('value', snap=>
{
if(document.getElementById('txtap').value==snap.val())
window.location = 'dashboard.html';
else
alert('invalid login');
});}
else{alert('invalid login');}
});
}
这是第二页代码,无效
var config = {
apiKey: "AIzaSyAPlhWdY7OVAEI_LrGMP073D5Ra6g",
authDomain: "mgf.firebaseapp.com",
databaseURL: "https://mgf.firebaseio.com",
projectId: "mgf",
storageBucket: "mgf.appspot.com",
messagingSenderId: "579064514788"
};
firebase.initializeApp(config);
function addofficer()
{
var e = document.getElementById("depto");
var dept = e.options[e.selectedIndex].value;
if(document.getElementById('radiom').checked=true){
var gender=document.getElementById('radiom').value;}
else{
var gender=document.getElementById('radiof').value;}
var uid=document.getElementById('uido').value;
var email=document.getElementById('emailo').value;
var pass=document.getElementById('passo').value;
var dob=document.getElementById('dobo').value;
var name=document.getElementById('nameo').value;
var mobile=document.getElementById('mobo').value;
var house=document.getElementById('houseo').value;
var street=document.getElementById('streeto').value;
var areaa=document.getElementById('areao').value;
var post=document.getElementById('pofco').value;
var vtc=document.getElementById('vtco').value;
var dist=document.getElementById('dsto').value;
var pin=document.getElementById('pco').value;
}
我是否必须在第二个文件中再次添加firebase初始化代码?