javascript - When to use atob, encodeURIComponent and btoa, decodeURIComponent -
when use atob, encodeuricomponent, btoa, decodeuricomponent. suppose used i.e., atob(encodeuricomponent(...))? if not, when atob&btoa used , when encodeuricomponent&decodeuricomponent used.
btoa()
encodes string of binary data in base-64 format. common use of creating data:
uri contents of file (e.g. turning jpeg or gif file data:
uri incorporate directly page instead of referencing remote file).
atob()
performs opposite: given base-64 string, returns binary data.
encodeuricomponent()
used perform url-encoding of strings used in uri. converts characters have special meaning in uris %
followed hex encoding, e.g. space becomes %20
. used when creating url parameters used in redirects or ajax requests, or data sent in xmlhttprequest.send()
.
decodeuricomponent()
performs reverse of encodeuricomponent()
, if have "foo%20bar"
return "foo bar"
.
it's pretty rare need use both url-encoding , base-64 same string.
Comments
Post a Comment