From old post: Should I use encodeURI or encodeURIComponent for encoding URLs?, it said:
encodeURI assumes that the input is a complete URI that might have some
characters which need encoding in it.
encodeURIComponent will encode everything with special meaning, so
you use it for components of URIs such as
What if I need to encode the URI
as query string parameter?
e.g.
var url = http://example.com/?next= + encodeURI(url)
or
var url = http://example.com/?next= + encodeURIComponent(url)