【the waiter】announcement:
| | |
Function introduction
- Use JavaScript's encodeURI and encodeURIComponent for encoding.
- Use JavaScript's decodeURIComponent to decode.
Method Introduction
encodeURI
- Purpose: Used to encode the entire URI. For example:
"http://example.com/This is a test? name= Zhang San "
. - Encoding rules: Only characters with special meaning in the URI will be encoded, such as spaces (encoded as
%20
),#
(encoded as%23
), etc. The following characters will not be encoded:A-Z
,a-z
,0-9
,-
,_
,.
!,
~,
*,
'、
(、
)、
;、
/、
?、
:、
@、
&、
=、
+、
$、
,`,Because these characters have a specific meaning in the URI.
encodeURIComponent
- Purpose: Used to encode part of the URI (such as the values of query parameters), rather than the entire URI. For example:
"name= Zhang San &age=25"
. - Encoding rules:
encodeURIComponent
encodes all non-alphanumeric characters, including;
,/
,?
:,
@,
&,
=,
+,
$,
,,
etc., because these characters have no special meaning in the URI component, they are all encoded.
decodeURIComponent
- Purpose: Used to decode individual URI components (such as the values of query parameters) and restore the characters encoded by
encodeURIComponent
to the original characters. - Decoding rules:
decodeURIComponent
will decode all characters encoded byencodeURIComponent
and convert the encoding starting with%
back to the corresponding character. For example,%20
will be decoded as spaces, and%3D
will be decoded as=
.