Home > Article > Web Front-end > What to do if jquery url is garbled in Chinese?
The solution to the Chinese garbled jquery url: first create an HTML page that passes parameters, and perform encodeURI transcoding twice; then in the HTML page that receives the parameters, use "decodeURI(_t);" to transcode once That’s it.
The operating environment of this article: Windows 7 system, jquery version 1.2.6, DELL G3 computer.
How to solve the problem of Chinese garbled characters in jquery url parameters?
jquery transfers address parameters through url (Chinese garbled processing)
1. Pass parameter page.html
<script type="text/javascript"> var name = 'abc'; //字符串英文 var num = 998; //数字 var cla= '电脑'; //中文 var _t = encodeURI(encodeURI(cla)); //中文需要进行两次encodeURI转码( encodeURI:把URI字符串采用UTF-8编码格式转化成escape格式的字符串。) window.location.href = "../aa.html?name=" + name(字符串) + "&num=num (数字)" + "&cla=_t (中文)"; </script>
2. Receive parameter page.html
(Final page address: ../aa.html?name=abc&num=998&cla=%E7%94%B5%E8%84%91)
<script type="text/javascript"> //获取地址参数 var _name = getQueryString("name"); var _num=getQueryString("num"); var _t = getQueryString("cla"); //此为中文参数,需转码 var title = decodeURI(_t); //只需要转一次码 console.log(title);//此处打印出来是中文。 function getQueryString(name) { //正则表达式,获取地址中的参数 var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } </script>
Recommended: "jquery video Tutorial》
The above is the detailed content of What to do if jquery url is garbled in Chinese?. For more information, please follow other related articles on the PHP Chinese website!