Firstly, apologies for the phrasing in the question – I couldn’t come up with anything better, sorry!
Here’s the scenario – I’m working with a JS Front-end that I have little control over, and a Coldfusion backend that I do control.
Everything is working fine, with one slight exception – which I’m hoping will be an easy fix! The database currently stores only the filename of an image, however the front-end requires the full url. Therefore, I somehow need to append the domain (which will always be the same) prior to SerializeJson. I’ve tried a few things without success so far, and haven’t been able to find any syntax examples.
My existing code is below;
<cfquery name="qryNames">
SELECT ID, imgthumb, imgfull
FROM images
ORDER BY ID DESC
</cfquery>
<cfset data = [] />
<cfoutput query="qryNames">
<cfset obj = {
"thumb" = ImgThumb,
"image" = Imgfull
} />
<cfset arrayAppend(data, obj) />
</cfoutput>
<cfprocessingdirective suppresswhitespace="Yes">
<cfoutput>
#serializeJSON(data)#
</cfoutput>
</cfprocessingdirective>
<cfsetting enablecfoutputonly="No" showdebugoutput="No">
For clarity, this is what I’m looking for…
<cfset obj = {
"thumb" = http://mydomain/ImgThumb,
"image" = http://mydomain/Imgfull
} />
Pointers much appreciated!
You can append things to variables like this:
Hopefully that works for you.