var databaseRef = firebase.database().ref("Test_Applicants/");
databaseRef.push({
firstname: first_name,
middlename: middle_name,
lastname: last_name,
university: university_full_name,
email: email_address,
phone: phone_number,
date: getDate(),
docs: docURL
}, function(error){
//Callback failed
console.error(error);
});
这是正确的做法吗?如何通过回调或通过任何其他方式从Firebase接收变量或参数以确认数据是否已成功写入?我希望在请求成功时上传文件,或者如果写入失败则向用户返回错误消息。
答案 0 :(得分:1)
This should work
var databaseRef = firebase.database().ref("Test_Applicants/");
databaseRef.push({
firstname: first_name,
middlename: middle_name,
lastname: last_name,
university: university_full_name,
email: email_address,
phone: phone_number,
date: getDate(),
docs: docURL
}, function(error){
if (error) {
console.error(error)
return
}
console.log('Push successful')
//add upload function here
});
答案 1 :(得分:0)
You can listen child events in this case using following
databaseRef.on('child_added', function(data) {
console.log(data);
});
More info: https://firebase.google.com/docs/database/web/lists-of-data#listen_for_child_events
答案 2 :(得分:0)
databaseRef.push().set({name:"john doe",telephone:"25400000000"}).catch((error)=>console.log(error))