|
|
 |
10-31-2012, 12:30 PM
|
#1
|
|
Lifer
Join Date: Oct 2002
Posts: 12,401
|
getJSON issue with complex URLs
I'm trying to get an AJAX function working, and it otherwise works except for when one of the included arguments is a string with a bunch of special characters (like a pw).
Code:
$.getJSON("http://company.com/access.cfc?method=checkUserCredentials&userID="+ #session.myID# + "&lastname=" + lastName + "&firstname=" + firstName+ "&email=" + email + "&password=" + password,function(checkUserCredentialsResults)
This works fine if the password doesn't contain any prohibition/special characters.
For instance.. 'test123' works fine, but 'test!@#456' gets truncated to 'test!@'
Do I need to encode this url?
__________________
Originally posted by: n0cmonkey
You're being difficult. You have not provided us with the information we need to troubleshoot the problem. You have not given us errors, you're vague about where the problem is, you are not answering the questions we ask. In short, you DON'T KNOW HOW TO THINK. Give back that piece of paper you think makes your intelligent, apologize, destroy your computer and go live in the woods kid.
|
|
|
10-31-2012, 01:16 PM
|
#2
|
|
Lifer
Join Date: Sep 2001
Location: ATX
Posts: 11,972
|
You need to encode every piece of data you put into a URL query string. That's what the definition of a URL is. I'm assuming that this sets up some sort of session on the server so I think you really should be using a POST request here anyways.
__________________
Consequences will never be the same!
/^1?$|^(11+?)\1+$/
|
|
|
10-31-2012, 02:23 PM
|
#3
|
|
Golden Member
Join Date: Jun 2009
Posts: 1,616
|
Quote:
Originally Posted by TechBoyJK
I'm trying to get an AJAX function working, and it otherwise works except for when one of the included arguments is a string with a bunch of special characters (like a pw).
Code:
$.getJSON("http://company.com/access.cfc?method=checkUserCredentials&userID="+ #session.myID# + "&lastname=" + lastName + "&firstname=" + firstName+ "&email=" + email + "&password=" + password,function(checkUserCredentialsResults)
This works fine if the password doesn't contain any prohibition/special characters.
For instance.. 'test123' works fine, but 'test!@#456' gets truncated to 'test!@'
Do I need to encode this url?
|
I just hope this application is not facing the internet...or its https.
http://stackoverflow.com/questions/3...-in-javascript
|
|
|
10-31-2012, 03:19 PM
|
#4
|
|
Lifer
Join Date: Oct 2002
Posts: 12,401
|
Yes, it would be moved to https before production.
__________________
Originally posted by: n0cmonkey
You're being difficult. You have not provided us with the information we need to troubleshoot the problem. You have not given us errors, you're vague about where the problem is, you are not answering the questions we ask. In short, you DON'T KNOW HOW TO THINK. Give back that piece of paper you think makes your intelligent, apologize, destroy your computer and go live in the woods kid.
|
|
|
10-31-2012, 07:16 PM
|
#5
|
|
Junior Member
Join Date: May 2012
Posts: 21
|
I'd also recommend using POST rather than GET. Either way, jQuery will handle the encoding if you let it build the request itself.
Code:
$.POST(
'http://company.com/access.cfc',
{
method : 'checkUserCredentials',
userID : '#session.myID#',
lastname : lastName,
firstname : firstName,
email : email,
password : password,
},
your callback,
'json'
);
Using getJSON works just as well, but you just need to change how you're feeding it the variables:
Code:
$.getJSON(
'http://company.com/access.cfc',
{
method : 'checkUserCredentials',
userID : '#session.myID#',
lastname : lastName,
firstname : firstName,
email : email,
password : password,
},
your callback
);
Last edited by Dratickon; 10-31-2012 at 07:25 PM.
|
|
|
11-03-2012, 04:31 PM
|
#6
|
|
Lifer
Join Date: Jul 2004
Location: Austin, TX
Posts: 20,278
|
Alternatively, if you want to be manual, you can call encodeURIComponent().
Code:
var url = "http://company.com/access.cfc?method=checkUserCredentials" +
"&userID=" + encodeURIComponent(#session.myID#) +
"&lastname=" + encodeURIComponent(lastName) +
"&firstname=" + encodeURIComponent(firstName) +
"&email=" + encodeURIComponent(email) +
"&password=" + encodeURIComponent(password);
$.getJSON(url ,function(checkUserCredentialsResults);
Last edited by Leros; 11-03-2012 at 06:10 PM.
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 06:07 PM.
|