我目前正在为我们的项目开发注册模块,这是我第一次使用Firebase作为后端进行编程。这里是我的注册表格中的代码HTML:无法将输入数据推送到我的Firebase数据库
<form class="innerContent">
<div class="inputTxt mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="tName">
<label class="inputLabel mdl-textfield__label" for="tName">Name of Tailor/Tailor Shop</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="tAddress">
<label class="inputLabel mdl-textfield__label" for="tAddress">Address of Tailor/Tailor Shop</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows= "3" id="tDesc"></textarea>
<label class="inputLabel mdl-textfield__label" for="tDesc">Description</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield">
<textarea class="mdl-textfield__input" type="text" rows= "3" id="tContact"></textarea>
<label class="inputLabel mdl-textfield__label" for="tContact">Contact Details</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="text" id="tUsername">
<label class="inputLabel mdl-textfield__label" for="tUsername">Username</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="password" id="tPassword">
<label class="inputLabel mdl-textfield__label" for="tPassword">Password</label>
</div>
<div class="inputTxt mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input" type="password" id="tRePassword">
<label class="inputLabel mdl-textfield__label" for="tRePassword">Re-type Password</label>
</div>
<p>
<input id="TaC" type="checkbox" for="TaC"> I have read the the <a href="#">Terms and Conditions</a>
<button id="SignUpBtn" class="farBtn mdl-button mdl-js-button mdl-button--raised mdl-button--colored mdl-js-ripple-effect" type="button" onclick="signUp()" disabled>
<i class="material-icons">done_all</i> Sign Up
</button>
</p>
</form>
我希望用户所有其信息登记到我的火力数据库。当按下注册按钮,它会在我的JavaScript触发此功能:
function signUp(){
var name = $("#tName").val();
var address = $("#tAddress").val();
var description = $("#tDesc").val();
var contact = $("#tContact").val();
var username = $("#tUsername").val();
var pword = $("#tPassword").val();
var tailors = notsDB.child("tailors");
tailors.push({
tName: name,
tAddreass: address,
tDescription: description,
tContact: contact,
tUsername: username,
tPassword: pword
});
但不幸的是,这是行不通的!我在Firebase控制台中查看了我的数据库,没有任何更改。我试图通过将auth != null
更换为true
来更改规则,但它不起作用。
抛开未能正确实施推送功能的可能性,我怀疑我没有正确连接到我的火狐账户。我召回了所有我在web应用程序连接到火力做的过程:
- 我在火力
- 我在我的电脑上安装的Node.js创建一个帐户
- 我把下面的代码片段在我HTML文件(在主体部分的底部,所有其他JavaScript之前)
<!-- FIREBASE -->
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.2.0/firebase-messaging.js"></script>
<script>
<!-- Initialize Firebase -->
var config = {
apiKey: "AIzaSyCM6Ublqz7PLkRgkzGe6vhsvb7iU0BU5Tk",
authDomain: "nots-eece8.firebaseapp.com",
databaseURL: "https://nots-eece8.firebaseio.com",
projectId: "nots-eece8",
storageBucket: "nots-eece8.appspot.com",
\t messagingSenderId: "472888671312"
};
firebase.initializeApp(config);
</script>
在我的web应用程序中设置firebase时,是否有任何程序跳过了?是否需要安装带有npm install firebase --save
的Firebase SDK?或者错误在于我的推送功能?
注:我已经把下面的代码我的注册方法之前在我的JavaScript文件:
var firebase = require('firebase');
var notsDB = new Firebase('https://nots-eece8.firebaseio.com');
@editor谁试图删除API密钥:这只是配置数据。见https://stackoverflow.com/questions/37482366/is-it-safe-to-expose-firebase-apikey-to-the-public –