nodejs怎么把html以源码的形式在网页中显示了,而不是解析它。
发布于 11 年前 作者 shen243212772 13909 次浏览 最后一次编辑是 8 年前

代码如下

var fs = require(‘fs’);

function start(response) { response.writeHead(200, {“Content-Type”: “text/plain”}); response.end(fs.readFileSync(__dirname + ‘/index.html’)); }

function upload(response) { response.writeHead(200, {“Content-Type”: “text/plain”}); response.end(fs.readFileSync(__dirname + ‘/index1.html’)); }

2 回复

想了下,原来是html文件头写错,改成 response.writeHead(200, {“Content-Type”: “text/html”}); 就好了

#为什么我render出来的文章列表是html以源码的形式在网页中呢,在html中被转义了,不知道如何解决,

回到顶部