我不斷收到此錯誤:錯誤:發送後無法設置標題。爲什麼?錯誤:發送後無法設置標題
我已閱讀其他帖子,但我不明白。我沒有任何雙重回調或任何東西。我的代碼在哪裏導致這個錯誤?
Error: Can't set headers after they are sent. at ServerResponse.OutgoingMessage.setHeader (http.js:689:11) at ServerResponse.header (/root/node_modules/express/lib/response.js:666:10) at ServerResponse.send (/root/node_modules/express/lib/response.js:146:12) at fn (/root/node_modules/express/lib/response.js:900:10) at View.exports.renderFile [as engine] (/root/node_modules/jade/lib/jade.js:330:12) at View.render (/root/node_modules/express/lib/view.js:93:8) at EventEmitter.app.render (/root/node_modules/express/lib/application.js:530:10) at ServerResponse.res.render (/root/node_modules/express/lib/response.js:904:7) at Query. (/root/tutsplus/server4.js:25:7) at Query.emit (events.js:98:17)
var express = require('express'), app = express();
var mysql = require('mysql');
app.get('/', function(req,res) {
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: 'fuck',
database: 'store'
});
var query = connection.query('SELECT * from category');
query.on('result', function(row) {
var category = row.category_name;
res.render('fuck.jade', {
category: category
});
});
}); // app.get
app.listen(80, function() {
console.log('we are logged in');
});
此特定錯誤是由於操作引起的事情失序在發送響應異步操作不當幾乎總是。 – jfriend00
我的代碼中是否有導致此問題的任何內容?我應該在哪裏看? – user3658794
請發佈錯誤的堆棧跟蹤('error.stack')。 – Dai