Turned from ZCCST and fell into encodeURIComponent's hole again.
Problem:
Ajax.get (url+ '? K1 ' =v1+ ' &k2 ' =v2+ ' &k3 ' =v3, ...);
Since the URL is only encodeURI encoded, the parameter you want to commit has Searchword = A+b, which becomes a B.
Workaround:
Ajax.post (URL, params,....)
Where the params is an object.
Cause: If the parameter is an object or an array, the component library has encodeuricomponent for you. And if you're just a string, the component library doesn't do anything, so the special characters are filtered to the back end.
encodeURI () usage
The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().
The purpose of this method is to fully encode the URI, so the encodeURI () function is not escaped for the following ASCII punctuation mark with a special meaning in the URI:;/?:@&=+$,#
Tip : If the URI component contains delimiters, such as? and #, each component should be encoded using the encodeURIComponent () method.
Example:
document.write (encodeURI ("http://www.w3school.com.cn") + "<br/>") document.write (encodeURI(" Http://www.w3school.com.cn/My first/")) document.write (encodeURI (",/?:@&=+$# " )) // annotation: Only the part after the domain name is converted, and the/?:@&=+$ #不处理. // http://www.w3school.com.cn // http://www.w3school.com.cn/My%20first/ // ,/?:@&=+$#
The decodeURI () function decodes a URI encoded by the encodeURI () function.
encodeURIComponent () usage
The method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation marks:-_. ! ~ * ' ().
Other characters (such as:;/?:@&=+$,# These punctuation marks used to separate the URI component) are replaced by one or more hexadecimal escape sequences.
tip : 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.
Example:
document.write (encodeURIComponent ("http://www.w3school.com.cn")) document.write (encodeURIComponent ( "http://www.w3school.com.cn/p 1/")) document.write (encodeURIComponent (",/?:@&=+$#")) // Compare // http%3a%2f%2fwww.w3school.com.cn // http%3a%2f%2fwww.w3school.com.cn%2fp%201%2f // %2c%2f%3f%3a%40%26%3d%2b%24%23
The decodeURIComponent () function decodes the URI encoded by the encodeURIComponent () function.
encodeURI and encodeURIComponent