【问题标题】:Return raw html with node (just html into a var)使用节点返回原始 html(只是将 html 转换为 var)
【发布时间】:2015-11-17 03:02:32
【问题描述】:

我正在尝试通过节点使用jade,但是当我运行此代码时,我得到了由jade beetwen'pre'标签解析的html。

var http = require('http');
var jade = require('jade');

http.createServer(function(request, response){
    response.writeHead(200, {'Content-Type': 'text/plain'});

    response.end(jade.renderFile('index.jade'));
}).listen(8124);

console.log('Server running at http://127.0.0.1:8124/');

如何让节点呈现原始 html 而不转义任何内容?

【问题讨论】:

    标签: javascript html node.js pug


    【解决方案1】:

    要呈现 HTML,您需要使用 'Content-Type': 'text/html; charset=UTF-8'。使用 text/plain 会将 HTML 呈现为纯文本(无需解释),并使其看起来好像 HTML 是在 <pre></pre> 标记之间呈现的。

    【讨论】:

    • 谢谢,我刚刚从文档中复制了该行,并且“没有读过哈哈”
    • 没问题,发生在我们最好的人身上:)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-15
    • 1970-01-01
    • 2021-11-30
    • 2021-02-24
    相关资源
    最近更新 更多