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