不随人意啊,还是入门问题,载入网页的时候标签都呼啦啦蹦出来了!
发布于 13 年前 作者 minmintemuer 4698 次浏览 最后一次编辑是 8 年前

源码:

var exec = require(“child_process”).exec; function start(response){ console.log(“Request handler ‘start’ was called.”); var body = ‘<html xmlns=“http://www.w3.org/1999/xhtml”>’+ ‘<head>’+ ‘<meta http-equiv=“Content-Type” content=“text/html;charset=gb2312”/>’+ ‘</head>’+ ‘<body>’+ ‘<form action="/upload" method=“post”>’+ ‘<textarea name=“text” rows=“20” cols=“60”></textarea>’+ ‘<input type=“submit” value=“Submit”/>’+ ‘</form>’+ ‘</body>’+ ‘</html>’; response.writeHead(200,{‘Content-Type’:‘text/plain’}); response.write(body); response.end(); console.log("‘start’ is over!"); } function upload(response){ console.log(“Request handler ‘upload’ war called.”); response.writeHead(200,{‘Content-Type’:‘text/plain’}); response.write(“Hello Upload!”); response.end(); } exports.start = start; exports.upload = upload;

显示:


![enter image description here][1] [1]: http://cnodejs.org/user_data/images/4f6ace5713664ea2702d8329/4f6ace5713664ea2702d83291333865891964.jpg

大神们,这是咋回事啊,我以为得能自动解析成网页才对啊!求解惑

2 回复

response.writeHead 处,你将 Content-Type 设为了 text/plain, 所以浏览器将其以纯文本的方式显示了。将其改为 text/html 就行了。

哈哈,小弟不好意思的笑了,基本功太不扎实了,谢谢大哥!

回到顶部