What is the JavaScript equivalent of C# Server.URLEncode?
3 Answers
No, encodeURIComponent() exactly.
2 Comments
Vineet Reynolds
I really find it hard to believe that this is your first answer after 476 questions. Surely it befits something more than this lousy comment of mine :D
RileyE
This question may become famous, simply because of this answer! However, isn't this answer more correct?
There’s a wonderful article on xkr.us comparing javascript’s various escape functions. Do read it for details, but here’s a quick summery:
escape()— don’t use: does not understand non-ASCII characters, and does not escape some important URI characters, such as+.encodeURI()— encodes an entire URI: as such, it leaves?and&unencoded.encodeURIComponent()— encodes a component in a query string (this is usually the one you want, and appears to be the equivalent ofServer.URLEncode).