js中post中文参数转码和解码

作为基础知识和血淋林的教训,前端一定要记得post请求时将参数中带有中文的部分进行转码!!

var str='宋宇·特弱夫斯基';

//转码:

encodeURI(encodeURI(str)) ; =>"%25E5%25AE%258B%25E5%25AE%2587%25C2%25B7%25E7%2589%25B9%25E5%25BC%25B1%25E5%25A4%25AB%25E6%2596%25AF%25E5%259F%25BA"

//解码:

decodeURIComponent(decodeURI("%25E5%25AE%258B%25E5%25AE%2587%25C2%25B7%25E7%2589%25B9%25E5%25BC%25B1%25E5%25A4%25AB%25E6%2596%25AF%25E5%259F%25BA"));=>"宋宇·特弱夫斯基"

 

posted @ 2018-06-05 23:04  宋宇  阅读(3348)  评论(0编辑  收藏  举报