encodeURI and decodeURI are used in pairs, because the address bar of the browser has Chinese characters, which can cause unexpected errors.
So you can encodeuri non-English characters into English code, decodeURI can be used to restore the characters back
first, the basic concept
encodeURI and decodeURI are used in pairs, because the browser's address bar has Chinese characters, you can have unexpected errors, so you can encodeuri non-English characters into English encoding,
decodeURI can be used to restore characters back. The encodeURI method does not encode the following characters: ":", "/", ";" and "?", and the encodeURIComponent method can encode these characters.
The decodeURI () method is equivalent to Java.net.URLDecoder.decode (uristring, "UTF-8");
The encodeURI () method is equivalent to Java.net.URLEncoder.encode (uristring, "UTF-8");
Ii. examples
var uristr = "http://www.baidu.com?name= Zhang San &num=001 zs"var uriec = encodeURI (uristr ); document.write ("encoded" +var uridc = decodeURI (Uriec); document.write ("decoded" +
Http://www.baidu.com?name=%E5%BC%A0%E4%B8%89&num=001%20zs after encoding
Decoded http://www.baidu.com?name= Zhang San &num=001 zs
Introduction to the use of encodeURI and decodeURI methods in JavaScript