我正在尝试将数据插入实时数据库firebase中,我已经设置了数据库规则,但是未插入任何数据,并且没有显示错误,请建议我该怎么做。 编码有什么问题吗?
数据库规则:
{
"rules": {
".read": true,
".write": true
}
}
javascript文件:
var firebaseConfig = {
//config
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
var title,description,budget,location,type,expiretime,category;
$("#insert").click(function()
{
title = document.getElementsByName("title").value;
description = document.getElementsByName("description").value;
var rootRef = firebase.database().ref().child("tasks");
var userId = firebase.auth().currentUser.uid;
var usersRef = rootRef.child(userID);
if(title!="")
{
var userData =
{
"title":title,
"description": description,
};
usersRef.set(userData, function(error){
if(error){
var errorCode = error.code;
var errorMessage = error.message;
console.log(errorCode);
console.log(errorMessage);
window.alert("Message:" +errorMessage);
}
else{
window.location.href="tasks.html";
}
});
}
else{
window.alert("form is incomplete");
}
});