问题:
今天做小程序的一个表单提交,有字段包含中文,在提交的过程中,查看数据库出现乱码。查找原因 是在后台接口接接收值的时候乱码了。
method: "post", //可以设置不同方式 如:get等
header: { 'content-type': 'application/x-www-form-urlencoded' },
原因:
如果设置content-type: application/x-www-form-urlencoded ,微信默认会为键值对进行Url编码,也就是说微信默认会为key-value 加上urlEncode,所以服务端要将键值对进行urlDecode
解决办法:
method: "post", //可以设置不同方式 如:get等
header: { 'content-type': 'application/x-www-form-urlencoded;charset=utf-8', },
网友评论