CNode

nodejs怎么把html以源码的形式在网页中显示了,而不是解析它。

Sshen243212772发布于13 年前最后回复13 年前2 回复14903 浏览0 收藏

代码如下

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)

S
shen243212772#1·13 年前

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

J
joecora#2·13 年前

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

参与回复
登录后即可参与回复。登录