code_junkie

Best practice: escape, or encodeURI / encodeURIComponent

Nov 10th, 2011
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. escape("% +&=");
  2.  
  3. encodeURI("http://www.google.com?var1=value1&var2=value2");
  4.  
  5. encodeURIComponent("var1=value1&var2=value2");
  6.  
  7. encodeURI("http://www.google.com/a file with spaces.html")
  8.  
  9. http://www.google.com/a%20file%20with%20spaces.html
  10.  
  11. http%3A%2F%2Fwww.google.com%2Fa%20file%20with%20spaces.html
  12.  
  13. param1 = encodeURIComponent("http://xyz.com/?a=12&b=55")
  14.  
  15. url = "http://domain.com/?param1=" + param1 + "&param2=99";
  16.  
  17. http://www.domain.com/?param1=http%3A%2F%2Fxyz.com%2F%Ffa%3D12%26b%3D55&param2=99
Add Comment
Please, Sign In to add comment