Sometimes there may be such a requirement that I use in the background:
CopyCode The Code is as follows: httputility. urlencode (STR, system. Text. encoding. utf8 );
Encode the URL. The front-end JS needs to use this content. In this case, it needs to be decoded:
Code copy Code the code is as follows: /**
* URL encoding
**/
shengutils. encode = function (unzipstr) {
var zipstr = "";
var strspecial = "! \ "# $ % & '() * +,/:; <=>? [] ^ '{| }~ % ";
var TT =" ";
for (VAR I = 0; I var CHR = unzipstr. charat (I);
var c = shengutils. stringtoascii (CHR);
tt + = CHR + ":" + C + "N";
If (parseint ("0x" + C)> 0x7f) {
zipstr + = encodeuri (unzipstr. substr (I, 1);
}else {
If (CHR = "")
zipstr + = "+ ";
else if (strspecial. indexof (CHR )! =-1)
zipstr + = "%" + C. tostring (16);
else
zipstr + = CHR;
}< br> return zipstr;
}
/**
* URL Decoding
**/
Shengutils. Decode = function (zipstr ){
VaR uzipstr = "";
For (VAR I = 0; I <zipstr. length; I ++ ){
VaR CHR = zipstr. charat (I );
If (CHR = "+ "){
Uzipstr + = "";
} Else if (CHR = "% "){
VaR ASC = zipstr. substring (I + 1, I + 3 );
If (parseint ("0x" + ASC)> 0x7f ){
Uzipstr + = decodeuri ("%" + ASC. tostring () + zipstr. substring (I + 3, I + 9). tostring ());;
I + = 8;
} Else {
Uzipstr + = shengutils. asciitostring (parseint ("0x" + ASC ));
I + = 2;
}
} Else {
Uzipstr + = CHR;
}
}
Return uzipstr;
}
Shengutils. stringtoascii = function (STR ){
Return Str. charcodeat (0). tostring (16 );
}
Shengutils. asciitostring = function (asccode ){
Return string. fromcharcode (asccode );
}