作者BloodyDawn (Σ(゚∀゚*) )
看板Ajax
标题[node] Express的中文网址变乱码
时间Thu Dec 24 16:59:38 2015
大家好,
最近在设定route时遇到了中文变乱码的问题,设定如下:
var express = require('express'),
router = express.Router(),
router.route('/' + encodeURIComponent('公司'))
.get(function(req, res) {
res.end();
});
结果:
Cannot GET /åå
router.route('/company/:name')
.get(function(req, res) {
console.log(req.params.name);
});
结果:
name变成乱码
不论哪种方法只要遇到中文就会变成奇怪的乱码
请问是否有办法解决呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 218.161.38.10
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Ajax/M.1450947585.A.5A1.html
1F:→ y2468101216: 可以不要用中文吗? 12/24 17:16
2F:→ BloodyDawn: 没有办法,上面要的Orz 12/24 18:11
3F:→ mmis1000: 档案有设成utf8吗? 12/24 19:13
4F:→ mmis1000: 如果真的不行,用 \uxxxx 来表示如何? 12/24 19:13
5F:→ BloodyDawn: 档案室utf8, \xxxx的方法我再试试,感谢~^^ 12/25 13:54
6F:推 johnny9144: 你收到之後的get应该是要decode不是encode吧 02/28 09:31
7F:→ johnny9144: 前端要串中文的时候要encodeURI後段收到要decodeURI 02/28 09:32