我无法在OnsenUI / monaca应用中连接我的firebase数据库。我查看了与此问题有关的其他线程,并确保我的呼叫已更新为firebase 3.x.x.但是,每次我尝试在开发中启动应用程序时,都会得到相同的firebase未定义错误。我对这一切都不熟悉,任何帮助都将不胜感激
的index.html
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>
<script>
//creates reference to firebase
var ref = new Firebase('https://monaca-cli-trial.firebaseio.com/');
// Initialize Firebase
var config = {
apiKey: "whateverapinumber",
authDomain: "myapp.firebaseapp.com",
databaseURL: "https://myapp.firebaseio.com",
storageBucket: "",
};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();
</script>
<script src="https://www.gstatic.com/firebasejs/3.3.0/firebase.js"></script>
<script src="components/loader.js"></script>
<script src="lib/onsenui/js/onsenui.min.js"></script>
<script src="lib/javascriptstuff.js"></script>
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
<link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
<link rel="stylesheet" href="css/style.css">
我得到的错误指向第19行,即firebase.initializeApp(config);
答案 0 :(得分:1)
我在您遇到错误的代码中详细发布了。此外,我建议观看频道firebase上的视频。 https://youtu.be/k1D0_wFlXgo
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="Content-Security-Policy" content="default-src * data:; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">
<!-- 1. Duplicates. Outdated version-->
<!--<script src="https://cdn.firebase.com/js/client/2.4.2/firebase.js"></script>-->
<!-- 2. Install the new version-->
<script src="https://www.gstatic.com/firebasejs/3.3.0/firebase.js"></script>
<script>
// 3. Remove it is not necessary. Are registered in the databaseURL .
// var ref = new Firebase('https://monaca-cli-trial.firebaseio.com/');
var config = {
/* 5. Install apiKey*/ apiKey: "whateverapinumber",
/* 6 Replace authDomain: "myapp.firebaseapp.com" on authDomain: "monaca-cli-trial.firebaseapp.com" */ authDomain: "monaca-cli-trial.firebaseapp.com",
/* 7 Replace databaseURL: "https://myapp.firebaseio.com" on databaseURL: "https://monaca-cli-trial.firebaseio.com/" */ databaseURL: "https://monaca-cli-trial.firebaseio.com/",
storageBucket: "",
};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();
</script>
<script src="components/loader.js"></script>
<script src="lib/onsenui/js/onsenui.min.js"></script>
<script src="lib/javascriptstuff.js"></script>
<link rel="stylesheet" href="components/loader.css">
<link rel="stylesheet" href="lib/onsenui/css/onsenui.css">
<link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css">
<link rel="stylesheet" href="css/style.css">
&#13;
答案 1 :(得分:0)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<!-- <link rel="stylesheet" href=""> -->
</head>
<body>
<label for="">Username</label><input type="text" name="username" id="username" value="" placeholder="">
<label for="">First Name</label><input type="text" name="firstname" id="firstname" value="" placeholder="">
<label for="">last Name</label><input type="text" name="lastname" id="lastname" value="" placeholder="">
<button id="save">save</button>
<button id="clear">clear</button>
<button id="load">load</button>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/3.7.2/firebase.js"></script>
<script>
// Initialize Firebase
// var config = {
// apiKey: "AIzaSyAq0r--LaHvc6udVUcZqe6V-j-oYI_8ZLs",
// authDomain: "firstfirebase-eac5d.firebaseapp.com",
// databaseURL: "https://firstfirebase-eac5d.firebaseio.com",
// projectId: "firstfirebase-eac5d",
// storageBucket: "firstfirebase-eac5d.appspot.com",
// messagingSenderId: "820643601987"
// };
// firebase.initializeApp(config);
// service cloud.firestore {
// match /databases/{database}/documents {
// match /{document==**} {
// allow read, write: if false;
// }
// }
// }
// Initialize Firebase
var config = {
apiKey: "AIzaSyAgYi4y5oqmD1_lStsLPku3ijtgeivuL0o",
authDomain: "userfirebase-dc252.firebaseapp.com",
databaseURL: "https://userfirebase-dc252.firebaseio.com",
projectId: "userfirebase-dc252",
storageBucket: "userfirebase-dc252.appspot.com",
messagingSenderId: "284706019886"
};
firebase.initializeApp(config);
var rootRef = firebase.database().ref();
$('#save').click(function(){
rootRef.set({
username: $('#username').val(),
firstname: $('#firstname').val(),
lastname: $('#lastname').val()
});
});
</script>
</body>
<iframe src="http://site.startupbug.net:6999/canvas/firebase/" style="width:100%;height:500px;"></iframe>
</html>