JS encoding text involves 3 functions: Escape,encodeuri,encodeuricomponent, corresponding 3 decoding functions: Unescape,decodeuri,decodeuricomponent
You need to use encodeURIComponent when passing parameters so that the combined URL will not be truncated by special characters such as #.
For example: <script language= "JavaScript" >document.write (' <a href= '/?logout&aid=7& u= ' +encodeuricomponent ("www.111cn.net") + ' "> Exit </a& gt; '); </script>
encodeURI can be used as a whole when URL jumps are made
For example: location.href= "/encodeuri" ("/s?word= Baidu &ct=21");
JS can use escape when using data
For example: History records in the search of Tibet.
Escape encodes a Unicode value other than 0-255 by outputting the%u**** format, in other cases the Escape,encodeuri,encodeuricomponent encoding results are the same.
The most used should be encodeuricomponent, which is to convert Chinese, Korean and other special characters into utf-8 format URL encoding, So if you need to use encodeURIComponent when passing parameters to the background, you need background decoding for utf-8 support (the form is encoded in the same way as the current page encoding)
Escape does not encode 69 characters: *+-./@_0-9a-za-z
encodeURI characters are not encoded with 82:!#$& ' () *+,-./:;=?@_~0-9a-za-z
There are 71 encodeuricomponent characters that are not encoded:! ' () *-._~0-9a-za-z
According to the instructions, I need the encodeURIComponent function.
According to the above mentioned
1. Browser, the URL of the form is the same as the page encoding
2. URLs sent in browsers using XMLHTTP are consistent with the browser default settings
3. The request URL and the server are consistent without garbled appearance
PS: The recommended use of encodeURIComponent (), with its encoded URL and PHP UrlEncode () function results consistent with the most convenient interaction.