1
다음은 Node.js 함수입니다. 나쁜 JSON 데이터가 삭제된다는 의미에서 작동하지만 실패한 메시지도 깜박입니다. 왜? 그들은 항상 인해 블록 범위에 동시에 발생하므로내 req.flash가 작동하지 않는 이유는 무엇입니까?
// Create document
app.post('/documents.:format?', loadUser, function(req, res) {
/////////////////////////added by adam
//tests to see if the inputed text is valid JSON data
data = req.body.d.data;
console.log("///////////" + data);
try {
type = JSON.parse(data);
console.log(type);
} catch (ex) {
console.log("bad json: "+data);
req.flash('Nope', 'Invalid JSON');
res.redirect('/documents');
return;
}
var d = new Document(req.body.d);
d.user_id = req.currentUser.id;
d.save(function() {
switch (req.params.format) {
case 'json':
res.send(d.toObject());
break;
default:
req.flash('info', 'Document created');
res.redirect('/documents');
}
});
은 유효한 메시지 유형이 '아니요'입니까? 대신 '오류'를 시도하십시오. – generalhenry
무엇이 유효한 메시지 유형입니까 – masylum
'/ 문서'에서'req.session'의'console.log'를 할 수 있습니까? – masylum