0

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

3
  • If it were encoding the percent sign, you should see %25%40 instead of %2540. newUrl is missing the protocol (http://), but that shouldn't cause the issue you're seeing. We may need to see more code. Commented Dec 16, 2014 at 21:19
  • When I first call the jquery param function and log the string it is encoded right meening that the @ is encoded as %40. Somewhere along the line the % of the %40 is getting encoded to %25 thats the reason its %2540 Commented Dec 17, 2014 at 6:45
  • I think the problem is on the URL that you're redirecting to; it probably didn't decode it properly. Commented Dec 17, 2014 at 7:10

1 Answer 1

1

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

newUrl = 'http://www.something.com?' + ...
Sign up to request clarification or add additional context in comments.

1 Comment

Even with the protocol encluded it still does the same

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.