日期:2014-05-16  浏览次数:20358 次

nodejs中文乱码
最近在研究nodejs,写了一个测试例子,结果中文都是乱码,不知如何解决
JScript code
var http = require("http");
http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write(
'<!doctype html>'+
'<html>'+
'<head>'+
'<meta charset="utf-8"/>'+
'<title>米诺</title>'+
'</head>'+
'<body>'+
'<a href="/home.js">主页</a>'+
'<a href="/contact.js">Contact</a>'+
'</body>'+
'</html>'); 
response.end(); }).listen(8888);
console.log("服务启动");

在浏览器中标题"米诺"和l链接"主页"都为乱码,控制台"服务启动"四个字显示为空行.
另外,有没有什么办法不用框架就可以让html和js代码分离,每写一句html都要用引号和加号忒麻烦.

------解决方案--------------------
第8行
<meta charset="utf-8"/>'+
中加utf-8改为gbk
------解决方案--------------------
看下你的JS文件是什么编码,我的是无BOM utf-8没这问题