Variable is breaking my js script

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I have this script that works fine until I add a particular variable to the string

$.getJSON("http://mydomain.at/config/cfc/images.cfc?method=makeProfilePic&userID="+ #getImageInfoResults.userID# +"&thumbnailServer="+ #getImageInfoResults.imageServer# +"&thumbnailFolder="+ #getImageInfoResults.folderID# +"&thumbnailFile="+ #getImageInfoResults.imageFile#,function(result){

Everything between ## is a coldfusion variable.

The last segment is what breaks it '"&thumbnailFile="+ #getImageInfoResults.imageFile#'

I narrowed it down to '#getImageInfoResults.imageFile#' is what's breaking it.

It's just a filename. I checked the variable and for a particular instance it's '38196830020_large.jpg'

So if I put that string place of the variable it breaks too. If I remove the '.' then it's fine.

Soooooo

Do I need to encode this variable? wrap the string differently?
 

PhatoseAlpha

Platinum Member
Apr 10, 2005
2,131
21
81
Is there an error message in the browser's error console? What behavior are you seeing on failure exactly?
 

GregGreen

Golden Member
Dec 5, 2000
1,682
3
81
Is there an error message in the browser's error console? What behavior are you seeing on failure exactly?

I have the same questions. Nothing you posted should break it from what I can tell.

Also, I'm curious what the ColdFusion output looks like after it's plopped in those variables. Without knowing that, can't tell if we are diagnosing a JS/jQuery problem or a CF problem.
 
Last edited:

TechBoyJK

Lifer
Oct 17, 2002
16,699
60
91
I have the same questions. Nothing you posted should break it from what I can tell.

Also, I'm curious what the ColdFusion output looks like after it's plopped in those variables. Without knowing that, can't tell if we are diagnosing a JS/jQuery problem or a CF problem.

Everything does work if I remove that last variable reference.

Code:
&thumbnailFile="+ #getImageInfoResults.imageFile#

Actually, it still works even with

Code:
&thumbnailFile="

The output of the variable is a filename. If I replace

Code:
#getImageInfoResults.imageFile#

with

Code:
myfilename.jpg

It breaks.

If I remove the '.' it works

Code:
myfilenamejpg

So I have to believe the . is breaking
 

Dratickon

Junior Member
May 13, 2012
21
0
0
You need to put the CF variable within the quotes.

Code:
"&thumbnailFile="+ #getImageInfoResults.imageFile#

Should be

Code:
"&thumbnailFile=#getImageInfoResults.imageFile#"

I'm also assuming that you've wrapped it with cfoutput. What looks to be happening is that your JS code is being interpreted as if myfile.jpg is a JS object written in dot notation. I'd imagine this might be happening anywhere that you're spitting out non-integer strings from CF into JS.

I'd also suggest passing in your url variables to getJSON using the object method rather than building your url string manually so everything gets url encoded.