What is the JavaScript equivalent of C# Server.URLEncode?
encodeURI()
http://xkr.us/articles/javascript/encode-compare/#ref-js-msdn
No, encodeURIComponent()
exactly.
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
).