escape()
Don't use it.
encodeURI()
Use encodeURI when you want a working URL. Make this call:
encodeURI("http://www.google.com/a file with spaces.html")
to get:
http://www.google.com/a%20file%20with%20spaces.html
Don't call encodeURIComponent since it would destroy the URL and return
http%3A%2F%2Fwww.google.com%2Fa%20file%20with%20spaces.html
encodeURIComponent()
Use encodeURIComponent when you want to encode a URL parameter.
param1 = encodeURIComponent("http://xyz.com/a=12&b=55")
Then you may create the URL you need:
url = "http://domain.com/param1=" + param1 + "¶m2=99";
And you will get this complete URL:
http://domain.com/param1=http%3A%2F%2Fxyz.com%2Fa%3D12%26b%3D55&param2=99