相关疑难解决方法(0)

不能在express.js中做多个res.send

3年前,我可以在express.js中做多个res.send.
甚至写一个setTimeout来显示实时输出.

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>');
Run Code Online (Sandbox Code Playgroud)

现在它将抛出:

Error: Can't set headers after they are sent
Run Code Online (Sandbox Code Playgroud)

我知道nodejs和express已更新.为什么现在不能这样做?还有其他想法吗?


找到解决方案,但"res.write"不在api参考http://expressjs.com/4x/api.html ...

:S

node.js express

27
推荐指数
2
解决办法
3万
查看次数

标签 统计

express ×1

node.js ×1