Why do I need to call encodeURI two times to solve the garbled problem
12834595
Note the difference between the encodeURIComponent () function and the encodeURI () function, which assumes that its arguments are part of a URI (such as a protocol, hostname, path, or query string). Therefore, the encodeURIComponent () function escapes punctuation marks that are used to separate the various portions of the URI.
One, encodeURI ()//escape characters in a URI
Syntax: encodeURI (URI)//This is often used to solve Chinese garbled problems when coding different AJAX requests.
var str1 = "Hello JavaScript"; var str2 = encodeURI (str1); document.write (STR2);
Second, decodeURI ()//decode the characters in a URI
Syntax: decodeURI (URI)
var str1 = "Hello JavaScript"; var str2 = encodeURI (str1); document.write (STR2); Output%e4%bd%a0%e5%a5%bdjavascript var str3 = decodeURI (str2); document.write ("<br/>" + str3) //output Hello JavaScript
Three, encodeURIComponent ()//Escape the characters in the URI component
var str1 = "Hello JavaScript"; var str2 = encodeURIComponent (str1); document.write (STR2); Output%e4%bd%a0%e5%a5%bdjavascript
Iv. decodeuricomponent ()//decode a character in a URI component
var str1 = "Hello JavaScript"; var str2 = encodeURIComponent (str1); document.write (STR2); Output%e4%bd%a0%e5%a5%bdjavascript var str3 = decodeuricomponent (str2); document.write ("<br/>" + str3) //output Hello JavaScript
V, Escape ()//Encode a string
Syntax: Escape (value);
var str = "JavaScript hello"; var str1 = Escape (str); document.write (STR1); javascript%20%u4f60%u597d
VI, Unecape ()//decode a string encoded by the escape () function
Window.onload = function () { var str = "JavaScript hello"; var str1 = Escape (str); document.write (STR1); javascript%20%u4f60%u597d var str2 = unescape (str1); alert (STR2); Popup JavaScript Hello }
"Go" encodeURI and decodeURI methods