亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

node.js輸出網頁后亂碼

node.js輸出網頁后亂碼

zetro 2016-08-25 19:30:43
var http = require("http");//負責創建web服務器,處理http相關任務 fs = require('fs');function load_album_list (callback){ console.log(2); fs.readdir( 'img','utf-8',function(err,files){ if(err){ callback(err); return; } callback(null,files); } );} function handle_incoming_request(req,res){ console.log(1); res.setCharacterEncoding("utf-8");? console.log("incoming request:" + req.method+ "" +req.url); load_album_list(function(err,albums){ if(err){ res.writeHead(503,{"Content-Type":"application/json;charset=utf-8"}); res.end(JSON.stringify(err) + "\n"); return; } var out = { error:null, data:{albums:albums} }; res.writeHead(200,{"Content-Type":"application/json"}); res.end("封測人"+JSON.stringify(out) + "\n"); }); }var s = http.createServer(handle_incoming_request);s.listen(3000);
查看完整描述

1 回答

已采納
?
疊加無限

TA貢獻1條經驗 獲得超0個贊

res.end("封測人"+JSON.stringify(out)?+?"\n");

你這里輸出的只是html的body里的內容,沒有設置<meta charset="utf-8">,改成

res.end('<!DOCTYPE?html><html><head><meta?charset="UTF-8"></head><body>'+JSON.stringify(out)+'</body></html>')


查看完整回答
反對 回復 2016-08-29
  • 1 回答
  • 0 關注
  • 2229 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號