Back
Can anyone tell me should I use encodeURI or encodeURIComponent for encoding URLs?
It depends on the usage you are looking for. If you use encodeURI, the input is assumed to be a complete URI. For encodeURIComponent, it encode all with special meaning which can be used with the below components:
var world = "A string with symbols & characters that have special meaning?";var uri = 'http://example.com/foo?hello=' + encodeURIComponent(world);
var world = "A string with symbols & characters that have special meaning?";
var uri = 'http://example.com/foo?hello=' + encodeURIComponent(world);
Interested in Java? Check out this Java tutorial by Intellipaat.
31k questions
32.8k answers
501 comments
693 users