3年前我可以在express.js中做多個res.send。
甚至寫一個setTimeout來顯示一個實時輸出。不能在express.js中做多個res.send
response.send('<script class="jsbin" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>');
response.send('<html><body><input id="text_box" /><button>submit</button></body></html>');
var initJs = function() {
$('.button').click(function() {
$.post('/input', { input: $('#text_box').val() }, function() { alert('has send');});
});
}
response.send('<script>' + initJs + '</script>');
現在,它會拋出:
Error: Can't set headers after they are sent
我知道和的NodeJS表示已經更新。爲什麼現在不能這樣做?任何其他想法?
找到的解決方案,但 「res.write」 不是API參考http://expressjs.com/4x/api.html ...
:S
是的,這聽起來像這可能是他想到的。我完全忘記了Node的'response.write';我的大腦在快遞地:/ – 2014-08-29 04:47:26
很酷,這是我想要的。但是,爲什麼它不是在API參考http://expressjs.com/4x/api.html#res.send ??? – emj365 2014-08-29 08:07:34
也許因爲我們應該使用'res.render'或'res.send',當我是新手時,我使用'res.write'。 @ emj365爲什麼不嘗試'res.render'? – osrpt 2014-08-29 11:41:59