4
我很喜歡這裏的常見問題。但我無法從任何地方獲得解決方案。 這是我的代碼:如果行不是空然後呈現代碼頁,否則執行另一個操作。發送快遞後無法設置標題
app.get('/send',function(req,res){
var code=req.query['c']; // -- get request from input
connection.query("use mynum");
var strQuery = "select * from table WHERE code='"+code+"' LIMIT 1";
connection.query(strQuery, function(err, rows){
if(err) {
throw err;
}else{
if(rows.length==1){
res.render('pages/code', {code : rows[0].code});
connection.end();
res.end();
}else {
// here is some actions
}
}
});
res.end();
});
堆棧跟蹤:
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:690:11)
at ServerResponse.header (C:\wamp\www\vin_number\node_modules\express\lib\re
sponse.js:666:10)
at ServerResponse.res.contentType.res.type (C:\wamp\www\vin_number\node_modu
les\express\lib\response.js:532:15)
at ServerResponse.send (C:\wamp\www\vin_number\node_modules\express\lib\resp
onse.js:121:14)
at fn (C:\wamp\www\vin_number\node_modules\express\lib\response.js:900:10)
at View.exports.renderFile [as engine] (C:\wamp\www\vin_number\node_modules\
ejs\lib\ejs.js:323:3)
at View.render (C:\wamp\www\vin_number\node_modules\express\lib\view.js:93:8
)
at EventEmitter.app.render (C:\wamp\www\vin_number\node_modules\express\lib\
application.js:530:10)
at ServerResponse.res.render (C:\wamp\www\vin_number\node_modules\express\li
b\response.js:904:7)
at Query._callback (C:\wamp\www\vin_number\server.js:102:6)
對不起,您遇到的問題到底是什麼? 「在快速發送後無法設置標題」,但它似乎只能以兩種情況之一發送,而如果「rows.length!== 1」,則應該能夠寫入標題。您是否可以包含代碼的這一部分,因爲您可能會錯誤地編寫標題 –
什麼是堆棧跟蹤? –