开发者

How can I send some HTML, render a view, then send more HTML in Express+Node.js?

I'm using Node.js+Express, and I've come across a case where I need to send some HTML, render a view, then send some more HTML in the one response.

The flow would be:

开发者_运维问答res.send('some html');
res.render('module.html', {});
res.send('more html');

Now I know that res.render supports a callback, so I could do:

res.render('module.html', {}, function () {
    res.send('more html');
});

But res.send() doesn't appear to. Is there a way to achieve this?


Like Raynos Said I would recommend looking into view partials. This video from Author TJ explains the basics.

As a sidenote res.send send a full response and then closes the connection. You can not be using that if you want to send more text after that.

How can I send some HTML, render a view, then send more HTML in Express+Node.js?


So you have to use node.js native res.write to do what you want instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜