Regarding the encoding results of ASP (Server.UrlEncode), PHP (urlencode()) functions, or the Chinese characters written directly into COOKIES through dynamic languages such as asp and php, when reading them with JS, you will encounter an encoding problem. , that is, the final string is encoded by urlencode, and sometimes it is necessary to read the data from JS on the client side.
This article will briefly talk about how to solve this problem in js through the system’s own functions.
I believe that friends who have encountered this problem should have some understanding. Currently, some custom functions under js are popular on the Internet to solve this problem, such as vbscript (URLDecode()), javascript (UrlDecode( ))wait. Neither of these two functions can communicate well with each other asp (Server.UrlEncode) and php (urlencode()).
About vbscript (function URLDecode()) and javascript (function UrlDecode()) will also be reproduced at the end of this article.
The protagonist of this article is javascript (UrlDecodedecodeURIComponent()). This function name is so common that I don’t really understand it personally. After all, there are many system functions in js and it is easy to miss it. Worry discovered this function by accident!
Encoding function: encodeURIComponent()
Decoding function: decodeURIComponent()
decodeURIComponent() Syntax