var http = require("http");//負(fù)責(zé)創(chuàng)建web服務(wù)器,處理http相關(guān)任務(wù) 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("封測(cè)人"+JSON.stringify(out) + "\n"); }); }var s = http.createServer(handle_incoming_request);s.listen(3000);
1 回答
已采納

疊加無限
TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超0個(gè)贊
res.end("封測(cè)人"+JSON.stringify(out)?+?"\n");
你這里輸出的只是html的body里的內(nèi)容,沒有設(shè)置<meta charset="utf-8">,改成
res.end('<!DOCTYPE?html><html><head><meta?charset="UTF-8"></head><body>'+JSON.stringify(out)+'</body></html>')
- 1 回答
- 0 關(guān)注
- 2237 瀏覽
添加回答
舉報(bào)
0/150
提交
取消