Ernie
Ernie

Reputation: 567

Double encoding of url parameters

Im trying to url encode a email address as a url parameter. Now what seems to be straight forward use of jquery param is proving to confuse me more as I go along.

Here is what Im trying

var toEncode = {
                    'email': '[email protected]',
                    'name': 'something'
               }

var newUrl = "http://www.example.com?" + $.param(toEncode);

window.location.href = newUrl;

I have seen that the newUrl is properly encoded but once passed to the address bar the @ symbol is %2540 instead of %40. Somewhere along the line the % of the %40 is getting encoded again and I cant seem to figure is out.

Hope there is light at the end of this rabbit hole.

EDIT - More info

The url is the pulled on the new address and the email address is put in a text box and displays as something%40something.com

--------SOLUTION-------- After loads of twiddling I found what caused the problem, modperl was rewriting the url on the backend as the flag to disable url rewriting was not disabled. This caused the encodeing to happen twice and thus the reason for the %2540

Upvotes: 0

Views: 2603

Answers (1)

zzzzBov
zzzzBov

Reputation: 179086

www.something.com is a relative path, you need to be sure that it includes the protocol as:

newUrl = 'http://www.something.com?' + ...

Upvotes: 1

Related Questions