JS/jQuery encode URL for getJSON

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
Hey Guys, I have a string with special characters that need to be passed via getJSON

Code:
$.getJSON("https://me.com/login.cfc?method=login&email=" + email + "&password=" + password,function(result){});

Basically, the 'password' variable has special characters in it. But I have other functions that may have special characters, so I need to know a best practice on how to deal with it.

What's the best way to encode that?
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
You want to use the method encodeURIComponent() on the string you want to encode.
 

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
You want to use the method encodeURIComponent() on the string you want to encode.

Thanks, I was about to do that, but saw this method

Code:
								$.getJSON(
									'http://my.com/login.cfc',
										{
										method : 'login',
										email : email,
										password : password,
										},
										function(result){

which seems to work!
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Thanks, I was about to do that, but saw this method

Code:
								$.getJSON(
									'http://my.com/login.cfc',
										{
										method : 'login',
										email : email,
										password : password,
										},
										function(result){

which seems to work!

I imagine they are encoding it within the implementation of that function.