Go Back   AnandTech Forums > Software > Programming

Forums
· Hardware and Technology
· CPUs and Overclocking
· Motherboards
· Video Cards and Graphics
· Memory and Storage
· Power Supplies
· Cases & Cooling
· SFF, Notebooks, Pre-Built/Barebones PCs
· Networking
· Peripherals
· General Hardware
· Highly Technical
· Computer Help
· Home Theater PCs
· Consumer Electronics
· Digital and Video Cameras
· Mobile Devices & Gadgets
· Audio/Video & Home Theater
· Software
· Software for Windows
· All Things Apple
· *nix Software
· Operating Systems
· Programming
· PC Gaming
· Console Gaming
· Distributed Computing
· Security
· Social
· Off Topic
· Politics and News
· Discussion Club
· Love and Relationships
· The Garage
· Health and Fitness
· Merchandise and Shopping
· For Sale/Trade
· Hot Deals with Free Stuff/Contests
· Black Friday 2014
· Forum Issues
· Technical Forum Issues
· Personal Forum Issues
· Suggestion Box
· Moderator Resources
· Moderator Discussions
   

Reply
 
Thread Tools
Old 10-31-2012, 12:30 PM   #1
TechBoyJK
Lifer
 
TechBoyJK's Avatar
 
Join Date: Oct 2002
Posts: 13,534
Default 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.
TechBoyJK is offline   Reply With Quote
Old 10-31-2012, 01:16 PM   #2
Crusty
Lifer
 
Crusty's Avatar
 
Join Date: Sep 2001
Location: ATX
Posts: 12,323
Default

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+$/
Crusty is offline   Reply With Quote
Old 10-31-2012, 02:23 PM   #3
beginner99
Platinum Member
 
Join Date: Jun 2009
Posts: 2,200
Default

Quote:
Originally Posted by TechBoyJK View Post
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
beginner99 is online now   Reply With Quote
Old 10-31-2012, 03:19 PM   #4
TechBoyJK
Lifer
 
TechBoyJK's Avatar
 
Join Date: Oct 2002
Posts: 13,534
Default

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.
TechBoyJK is offline   Reply With Quote
Old 10-31-2012, 07:16 PM   #5
Dratickon
Junior Member
 
Join Date: May 2012
Posts: 21
Default

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.
Dratickon is offline   Reply With Quote
Old 11-03-2012, 04:31 PM   #6
Leros
Lifer
 
Leros's Avatar
 
Join Date: Jul 2004
Location: Austin, TX
Posts: 21,560
Default

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.
Leros is online now   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 10:08 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.