@ firebase / database:FIREBASE警告:用户抛出了异常 打回来。错误:发送后无法设置标头。在 ServerResponse.setHeader(_http_outgoing.js:371:11)at ServerResponse.header(C:\ Users \ G I ServerResponse.send上的E \ node_modules \ express \ lib \ response.js:725:10) (C:\ Users \ G I E \ node_modules \ express \ lib \ response.js:170:12)at at ServerResponse.json(C:\ Users \ G I E \ node_modules \ express \ lib \ response.js:256:15)在C:\ Users \ G I E \ Desktop \ firebase \ app \ server.js:47:13在C:\ Users \ G我 Ë\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS的\ src \核心\图\ EventRegistration.js:65:22 at Object.exports.exceptionGuard(C:\ Users \ G I Ë\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS的\ src \核心\ UTIL \ util.js中:536:9) 在EventList.raise(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:158:24) 在EventQueue.raiseQueuedEventsMatchingPredicate_(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:111:41) 在EventQueue.raiseEventsForChangedPath(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:95:14) C:\ Users \ G I Ë\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS的\ src \核心\ UTIL \ util.js中:547 扔掉; ^错误:发送后无法设置标头。在 ServerResponse.setHeader(_http_outgoing.js:371:11)at ServerResponse.header(C:\ Users \ G I ServerResponse.send上的E \ node_modules \ express \ lib \ response.js:725:10) (C:\ Users \ G I E \ node_modules \ express \ lib \ response.js:170:12)at at ServerResponse.json(C:\ Users \ G I E \ node_modules \ express \ lib \ response.js:256:15)在C:\ Users \ G I E \ Desktop \ firebase \ app \ server.js:47:13在C:\ Users \ G我 Ë\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS的\ src \核心\图\ EventRegistration.js:65:22 at Object.exports.exceptionGuard(C:\ Users \ G I Ë\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS的\ src \核心\ UTIL \ util.js中:536:9) 在EventList.raise(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:158:24) 在EventQueue.raiseQueuedEventsMatchingPredicate_(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:111:41) 在EventQueue.raiseEventsForChangedPath(C:\ Users \ G I È\桌面\火力\ node_modules \ @firebase \数据库\ DIST \ CJS \ SRC \芯\视图\ EventQueue.js:95:14)
我只是在提交表单中显示控制台中显示的错误
后,尝试将数据保存到firebase这是我的功能代码
app.post('/AddNewCountry',function(req,res){
var cid = firebase.database().ref().child('country').push().key;
var data = {
country_id: cid,
country_name: req.body.name,
country_flag: req.body.img
}
var updates = {};
updates['/country/' + cid] = data;
firebase.database().ref().update(updates);
console.log('The country is created successfully!');
})
任何帮助?
答案 0 :(得分:0)
看起来非常正确,除非req.body.name
或req.body.img
两者在保存到数据库时不应该是undefined
。因此,在保存之前,请检查值:
app.post('/AddNewCountry',function(req,res){
var cid = firebase.database().ref().child('country').push().key;
var data = {
country_id: cid,
country_name: req.body.name,
country_flag: req.body.img
}
if (req.body.name && req.body.img) {
var updates = {};
updates['/country/' + cid] = data;
firebase.database().ref().update(updates);
console.log('The country is created successfully!');
}
})