EncodeURI and encodeURIComponent the difference?

encodeURI method does the following character encoding ASCII letters, digits, ~ @ # $ & * () =:!? /,; + '
 
the encodeURIComponent method does the following character encoding ASCII letters, numbers, ! ~ * ()' 

so encodeURIComponent range greater than encodeURI coding. 

Practical examples for, encodeURIComponent will http: // encoded into http% 3A% 2F% 2F and encodeURI does not. 

If you need to encode the entire URL, then need to use the URL, then use encodeURI. 

When you need to encode the URL parameters, then the best way to encodeURIComponent

 

Guess you like

Origin www.cnblogs.com/yxdlm/p/10929119.html