Url encoding in Javascript
Posted: Fri Feb 17, 2006 9:30 am
I've been getting into AJAX recently and I've stumbled upon a simple problem.
I need to be able to pass strings potentially containing via the query string, characters which escape() alone won't convert to the Hex equivalent.
Googling has so far come up with a number of sites that provide converters where you paste your string and marvel at their encoding magic, but none of them have made their code public. I have looked into the source of one page but I'm reluctant to copy the code cos its more than I need and I don't fully understand it anyway.
Can someone explain the very basics of converting just the above characters into url safe codes?
I know it will involve String.charCodeAt and String.fromCharCode but thats about as much as I understand.
I need to be able to pass strings potentially containing
Code: Select all
* @ - _ + . /Googling has so far come up with a number of sites that provide converters where you paste your string and marvel at their encoding magic, but none of them have made their code public. I have looked into the source of one page but I'm reluctant to copy the code cos its more than I need and I don't fully understand it anyway.
Can someone explain the very basics of converting just the above characters into url safe codes?
I know it will involve String.charCodeAt and String.fromCharCode but thats about as much as I understand.