无法在Firebase上上传数据?

时间:2019-01-16 19:14:50

标签: javascript html firebase firebase-realtime-database

我正在尝试在Firebase上上传简单的表单数据,但事实是我什至没有收到任何错误或任何数据上传或确认警报框。

有什么建议我做错了吗?

我正在使用Firebase实时数据库,并遵循其文档

这是我的Firebase实时数据库的链接。

  

https://iet-workshop.firebaseio.com/

var name = document.getElementById("name");
var email = document.getElementById("email");
var msg = document.getElementById("comment");

function submitClick(){
	

	var nameTxt = name.value;
	var emailTxt = email.value;
	var msgTxt = msg.value;

	writeUserData(nameTxt,emailTxt,msgTxt);

}

function writeUserData(name, email, msg) {
  firebase.database().ref('users/' + userId).set({
    username: name,
    email: email,
    comment : msg
  }, function(error){
  	if(error){
  		// write failed
  		alert("Sorry unable to write data error = ",error);
  	}else{
  		// data saved successfully
  		alert("Thanks for your feedback");
  	}
  });
}
body{
	background: royalblue;
}

.form-style-6{
	font: 95% Arial, Helvetica, sans-serif;
	max-width: 400px;
	margin: 10px auto;
	padding: 16px;
	background: #F7F7F7;
}
.form-style-6 h1{
	background: #43D1AF;
	padding: 20px 0;
	font-size: 140%;
	font-weight: 300;
	text-align: center;
	color: #fff;
	margin: -16px -16px 16px -16px;
}
.form-style-6 input[type="text"],
.form-style-6 input[type="date"],
.form-style-6 input[type="datetime"],
.form-style-6 input[type="email"],
.form-style-6 input[type="number"],
.form-style-6 input[type="search"],
.form-style-6 input[type="time"],
.form-style-6 input[type="url"],
.form-style-6 textarea,
.form-style-6 select 
{
	-webkit-transition: all 0.30s ease-in-out;
	-moz-transition: all 0.30s ease-in-out;
	-ms-transition: all 0.30s ease-in-out;
	-o-transition: all 0.30s ease-in-out;
	outline: none;
	box-sizing: border-box;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	width: 100%;
	background: #fff;
	margin-bottom: 4%;
	border: 1px solid #ccc;
	padding: 3%;
	color: #555;
	font: 95% Arial, Helvetica, sans-serif;
}
.form-style-6 input[type="text"]:focus,
.form-style-6 input[type="date"]:focus,
.form-style-6 input[type="datetime"]:focus,
.form-style-6 input[type="email"]:focus,
.form-style-6 input[type="number"]:focus,
.form-style-6 input[type="search"]:focus,
.form-style-6 input[type="time"]:focus,
.form-style-6 input[type="url"]:focus,
.form-style-6 textarea:focus,
.form-style-6 select:focus
{
	box-shadow: 0 0 5px #43D1AF;
	padding: 3%;
	border: 1px solid #43D1AF;
}

.form-style-6 input[type="submit"],
.form-style-6 input[type="button"]{
	box-sizing: border-box;
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	width: 100%;
	padding: 3%;
	background: #43D1AF;
	border-bottom: 2px solid #30C29E;
	border-top-style: none;
	border-right-style: none;
	border-left-style: none;	
	color: #fff;
}
.form-style-6 input[type="submit"]:hover,
.form-style-6 input[type="button"]:hover{
	background: #2EBC99;
}
<!DOCTYPE html>
<html>
<head>
	<title>IET Workshop</title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
	<div class="form-style-6">
		<h1>Contact Us</h1>
		<form>
			<input id="name" type="text" name="field1" placeholder="Your Name" />
			<input id="email" type="email" name="field2" placeholder="Email Address" />
			<textarea id="comment" name="field3" placeholder="Type your Message"></textarea>
			<input id='submitBtn' type="submit" value="Send" onclick="submitClick()" />
		</form>
	</div>
</body>


<script src="https://www.gstatic.com/firebasejs/5.7.3/firebase.js"></script>
<script>
  // Initialize Firebase
  var config = {
    apiKey: "AIzaSyD83SJTFRLbWE2oh8ov7IPBBNQaSX_kpBs",
    authDomain: "iet-workshop.firebaseapp.com",
    databaseURL: "https://iet-workshop.firebaseio.com",
    projectId: "iet-workshop",
    storageBucket: "iet-workshop.appspot.com",
    messagingSenderId: "569222277610"
  };
  firebase.initializeApp(config);
</script>
<script type="text/javascript" src="main.js"></script>
</html>

1 个答案:

答案 0 :(得分:3)

这听起来像是规则不允许访问数据库的典型情况。检查规则,并确保其允许写入

when(submissionService.findSubmission(Mockito.anyLong())).thenReturn(submission[0], submission[1], submission[2], submission[3], submission[4])