JavaScript URL Encoding

Mar2409Mar 24, 09

I ran into a problem today while creating an automatic form AJAXify script. For most situations, you won't notice the differences between JavaScript's escape() and encodeURIComponent() functions - that is, until you try to pass special characters through them. After some trial and error, I realized the script should have been using encodeURIComponent(), namely because I was encoding a component of the URI (amazing realization, for sure). I hope that saves someone a bit of time.

For further reading, the script I was writing automatically converts all HTML form within a specified region into pretty AJAX submissions (technically the implementation uses AJAH, but the script supports both). I imagine there is already a jQuery function that does the same thing, but I preferred to keep the whole job encapsulated within a single object and I don't like referencing elements by their attributes all the time. This particular script is being created for the new version of CommunitY, my forum app. The code needed updates badly, and I figured it would be nice to convert the entire thing to a progressively enhanced web app, so that's what it has become. The new version should be up and running here.

About Jason Miller:

I am a JavaScript developer from Waterloo, Ontario, Canada. When I am not typing green code onto a black screen, you might find me at the nearest coffee pub checking out the brew. I run a internet firm called developIT and maintain blogs and web apps when I can.
Comments
Leave a Comment

Post Comment