views:

44

answers:

1

My application uses ajax and refreshes some parts of a template. Now I need to make an URL hash containing some variables that will be used for refreshing a page after a page is loaded that contains a hash.

Now I need a javascript procedure for making a hash.

  1. How to serialize variables?

  2. How to encode that serialized string?

I'm using jquery, maybe there is a solution already?

A: 

Serializing can be easily accomplished using JSON. I would encode the string using the simple, built-in functions escape and unescape. If you want to obfuscate it more, you can try base64, but that may not be necessary for your application

One things to consider is that whenever you pass content via the URL, you open up your application for HTML and script injection (XSS). You may want to consider a different approach.

Justin Johnson