下面的代码返回消息“错误:发送后无法设置标头。”
为什么??我的英语不好 。所以让我用日语写。对不起。
にれ値2 2种类のに変えてて,,値をををキーキーにににににににににににからからからから削除削除しようようとと以下ののコードをを书い书い书いたたが,上上が违っエラーページへ飞ばしてうまくうまくいっ×res.redirect('back')でで元の画面ににたいのですががが,,よいよいよいアドバイスがありありましましたらたらたらごご
app.post('/thread/remove', function(req, res, next) {
var deletethread = req.param('deletethread'),
deletepost = req.param("delete_post"),
localpassword = req.param('localpassword'),
category_id = req.param('category_id'),
arraydeletethread = String(deletethread).split(","),
arraydeletepost = String(deletepost).split(","),
error_flag = false;
console.log("arraydeletethread = " + arraydeletethread + ", arraydeletethread.length = " + arraydeletethread.length);
if (deletethread) {
if(arraydeletethread.length > 0) {
async.forEachSeries(arraydeletethread, function(val, callback) {
if (val) {
ThreadModel.findOne({post_id: Number(val)}, function(err, threadResult) {
if(err) {
console.log('error');
return next(err);
}
if (threadResult.password !== localpassword) {
error_flag = true;
req.flash('errors', 'wrong password');
req.flash('category_id', category_id);
return res.redirect("/post/error");
} else {
threadResult.remove();
console.log('remove suceeded!');
}
});
}
}, function() {
console.log('thread remove finished!');
});
}
}
console.log("arraydeletepost = " + arraydeletepost + ", arraydeletepost.length = " + arraydeletepost.length);
if (deletepost) {
if(arraydeletepost.length > 0){
async.forEachSeries(arraydeletepost, function(val, callback) {
if (val) {
var arraydeletepost_i = String(val).split("_");
ThreadModel.findOne({'replies.post_id': Number(arraydeletepost_i[1]), "post_id": Number(arraydeletepost_i[0])}, function(err, replyResult){
if(err) {
console.log('error');
return next(err);
}
if (replyResult.password !== localpassword) {
error_flag = true;
req.flash('errors', 'wrong password');
req.flash('category_id', category_id);
return res.redirect("/post/error");
} else {
ThreadModel.update({post_id: Number(arraydeletepost_i[0])},{$pull: {replies: {post_id: Number(arraydeletepost_i[1])}}}, function(err){
if(err) {
console.log('error');
return next(err);
}
console.log('remove suceeded!');
});
}
});
}
}, function() {
console.log('post remove finished!');
});
}
}
return res.redirect('back');
});
我像这样更改了我的代码。和错误情况很顺利,但是从mongodb正常系统中删除后,该过程不再返回并且不会返回上一个屏幕。(谷歌翻译)エラーケースはうまくいきましたが、正常系はmongodbから削除できたあとに前の画面に戻らずが帰ってこなくた...たましし
app.post('/thread/remove', function(req, res, next) {
var deletethread = req.param('deletethread'),
deletepost = req.param("delete_post"),
localpassword = req.param('localpassword'),
category_id = req.param('category_id'),
arraydeletethread = String(deletethread).split(","),
arraydeletepost = String(deletepost).split(",");
console.log("arraydeletethread = " + arraydeletethread + ", arraydeletethread.length = " + arraydeletethread.length);
console.log("arraydeletepost = " + arraydeletepost + ", arraydeletepost.length = " + arraydeletepost.length);
async.parallel([
function(callback) {
if (deletethread) {
if(arraydeletethread.length > 0) {
async.forEachSeries(arraydeletethread, function(val, callback) {
if (val) {
ThreadModel.findOne({post_id: Number(val)}, function(err, threadResult) {
if(err) {
console.log('error');
return callback("err = " + err);
} else {
if (threadResult.password !== localpassword) {
console.log('wrong password error');
return callback(new Error("wrong password error"));
} else {
threadResult.remove();
console.log('remove suceeded!');
callback();
}
}
});
}
}, function() {
console.log('forEach thread finished');
});
}
}
},
function(callback) {
if (deletepost) {
if(arraydeletepost.length > 0){
async.forEachSeries(arraydeletepost, function(val, callback) {
if (val) {
var arraydeletepost_i = String(val).split("_");
ThreadModel.findOne({'replies.post_id': Number(arraydeletepost_i[1]), "post_id": Number(arraydeletepost_i[0])}, function(err, replyResult){
if(err) {
console.log('error');
return callback(err);
} else {
if (replyResult.password !== localpassword) {
console.log('wrong password error');
return callback(new Error("wrong password error"));
} else {
ThreadModel.update({post_id: Number(arraydeletepost_i[0])},{$pull: {replies: {post_id: Number(arraydeletepost_i[1])}}}, function(err){
if(err) {
console.log('error');
return callback(err);
} else {
console.log('remove suceeded!');
callback();
}
});
}
}
});
}
}, function() {
console.log('forEach post finished');
});
}
}
}
],function(err) {
if (err) {
if (err.message === 'wrong password error') {
req.flash('errors', 'パスワードが違います。');
req.flash('category_id', category_id);
return res.redirect("/post/error");
} else {
return next(err);
}
} else {
res.redirect('back');
}
});
});