在ajax请求中经常遇到中文与URI编码没有转换从而遇到问题。
中文转化成URI编码两种方式
let a = encodeURI('哈哈')
let b = encodeURIComponent('哈哈')
console.log(a,b) 输出为 '%E5%93%88%E5%93%88 %E5%93%88%E5%93%88'
可以看出每个中文会被装换成为一个'%E5%93%88'形式的字符串。
URI编码转中文同样也有两种装换方式
let c = decodeURI('%E5%93%88%E5%93%88')
let d = decodeURIComponent('%E5%93%88%E5%93%88')
console.log(c,d) 输出为'哈哈' '哈哈'