declaration
- https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31/**
* Gets the unencoded version of an encoded Uniform Resource Identifier (URI).
* @param encodedURI A value representing an encoded URI.
*/
declare function decodeURI(encodedURI: string): string;
/**
* Gets the unencoded version of an encoded component of a Uniform Resource Identifier (URI).
* @param encodedURIComponent A value representing an encoded URI component.
*/
declare function decodeURIComponent(encodedURIComponent: string): string;
/**
* Encodes a text string as a valid Uniform Resource Identifier (URI)
* @param uri A value representing an encoded URI.
*/
declare function encodeURI(uri: string): string;
/**
* Encodes a text string as a valid component of a Uniform Resource Identifier (URI).
* @param uriComponent A value representing an encoded URI component.
*/
declare function encodeURIComponent(uriComponent: string | number | boolean): string;
# encodeURIComponent 转义除了如下所示外的所有字符:
# 不转义的字符:
# A-Z a-z 0-9 - _ . ! ~ * ' ( )
# 为了避免服务器收到不可预知的请求,对任何用户输入的作为URI部分的内容你都需要用encodeURIComponent进行转义
encodedURI vs encodedURIComponent
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI
1
Note that encodeURI() by itself cannot form proper HTTP GET and POST requests, such as for XMLHttpRequest, because "&", "+", and "=" are not encoded, which are treated as special characters in GET and POST requests. encodeURIComponent(), however, does encode these characters.
ASCII
- American Standard Code for Information Interchange
- https://en.wikipedia.org/wiki/ASCII
- 2^8
- 美国 - 服务于英文字符