Skip to main content
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes and Ezra Parker and Dan Wilson and John Mason and Jason Dean and Luis Majano and Mark Mandel and Brian Kotek and Wil Genovese and Rob Brooks-Bilson and Andy Matthews and Simeon Bateman and Ray Camden and Chris Rockett and Joe Bernard and Dan Skaggs and Byron Raines and Barney Boisvert and Simon Free and Steve 'Cutter' Blades and Seth Bienek and Katie Bienek and Jeff Coughlin
Ben Nadel at cf.Objective() 2010 (Minneapolis, MN) with: Doug Hughes Ezra Parker Dan Wilson John Mason Jason Dean Luis Majano Mark Mandel Brian Kotek Wil Genovese Rob Brooks-Bilson Andy Matthews Simeon Bateman Ray Camden Chris Rockett Joe Bernard Dan Skaggs Byron Raines Barney Boisvert Simon Free Steve 'Cutter' Blades Seth Bienek Katie Bienek Jeff Coughlin

JavaScript encodeURIComponent() Escapes "+" Symbol

By
Published in Comments (1)

I just blogged about how I was going to have to manually escape the "+" symbol when passing values from my AJAX web page to my ColdFusion back end, but I just happened upon a Javascript method that I have never seen before:

encodeURIComponent()

According to http://xkr.us/articles/javascript/encode-compare/, this method was introduced in Javascript 1.5. Here is a small description from the site:

Lastly, the encodeURIComponent() method should be used in most cases when encoding a single component of a URI. This method will encode certain chars that would normally be recognized as special chars for URIs so that many components may be included. Note that this method does not encode the ' character, as it is a valid character within URIs.

This seems to do the trick. Sweet-ass find!

Reader Comments

21 Comments

Just used this to pass JSON through the URL. Dumped URL scope on the receiving page and get something looking like this:

{"street_number":32,"viewport":"","administrative_area_level_1":"Auckland","country_short":"NZ","route":"Vialou Ln"}

Wondering how to work with this data, i.e. if there's an easy way to parse the separate variables out into useable format without a lot of list functions and suchlike.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed hosting services provided by:
xByte Cloud Logo