URL encoding in Javascript

I mentioned this in my Ajax and eCards talk, but if you’ve ever had to encode querystring of anything that isn’t ascii, you’ve run into troubles with encode(). The solution is to use encodeURIComponent().

Here is an article that outlines the difference between the three escaping functions.

The quick summary is, don’t use escape() use encodeURI() to encode URLs or encodeURIComponent() when encoding string parts that form a query string. In Ajax, always use the latter and form the string yourself.

Published by

tychay

light writing, word loving, ❤ coding

Leave a Reply

Your email address will not be published. Required fields are marked *