Escape (), encodeURI (), encodeURIComponent () Three methods can filter some special characters that affect URL integrity. But the latter two is the way to convert the string to UTF-8, which solves the problem of garbled page encoding.
For example: The sending page is inconsistent with the encoding format (Charset) of the Accept page (assuming that the sending page is GB2312 and the receiving page encoding is UTF-8), and using the escape () conversion will cause garbled problems with the text string in transit.
Here are the various ways to encode/decode URLs under JS:
Escape method: For @*+/A-Z 0-9 A-Z These characters are not encoded, other non-ASCII characters are encoded to%XX encoding substitution, decoding using the Unescape,escape method cannot be used to encode a "Uniform Resource Identifier" (URI). The encoding should use the encodeURI and encodeURIComponent methods. encodeURI (): Yes! @ # $ & * () =:/;? + ' A-Z 0-9 A-Z, other characters will be encoded, decoded using decodeURI ();
If you want to make more words to be encoded, for example:/, use the encodeURIComponent () method, after being encoded by this method, the parameter passed to the server is an invalid character, decoding using decodeURIComponent ()
JS processing URL Practical Tips