Requires two times encodeURI () encoding and two decodeURI () decoding,
When using encodeURI () encoding,
var searchtype = $ ("#type_select option:selected"). Val (); // "Base News" var searchcontent = $ ("#search_val"). Val (); // "AAAA" var url = encodeURI ("textsearchdetail.aspx?searchtype=" + searchtype + "&content=" + searchcontent); var enurl = encodeuri (URL),//used two times Encoderui to encode = Enurl;
When using decodeURI () decoding,
$(function () { varPostData =getrequest (); Console.log (PostData); Console.log (Postdata.searchtype); Console.log (postdata.content);})functiongetrequest () {var url =decodeuri (decodeURI (Location.search)); //gets the URL in the "?" The string after the Decoderui, using two times the decoding varTherequest =NewObject (); if(Url.indexof ("?")! =-1) { varstr = URL.SUBSTR (1); STRs= Str.split ("&"); for(vari = 0; i < strs.length; i++) {Therequest[strs[i].split ("=") [0]] = unescape (strs[i].split ("=") [1]); } returntherequest; }}
The output is:
Object {searchtype: "base dynamic", Content: "AAAA"}
Solve the problem that JS parameter contains Chinese garbled characters when passing parameters in URL