weekapaug
asked on
How to generate a JSON response in coldfusion
I have a page that needs to relay json info and it looks like this
<cffile action="uploadAll"
destination="C:/inetpub/ww wroot/real tye-mails/ ezupload/# zip#/#mlsn um#"
nameconflict="overwrite"
filefield="files"
result="uploadResult"/>
<cfoutput>#serializeJSON(u ploadResul t)#</cfout put>
When I look in firefox I see the information is there and appears to be correct but I was told it needs to be shown in the format below. Can anyone give me an example of code on how to take that coldfusion variable and somehow format it to be layed out like shown below?
I'm in way over my head on this one. I dont know how or where to go to get the result from the upload to have it transformed into what is shown below. No other information is provided and I'm in over my head on this one.
{"files": [
{
"name": "picture1.jpg",
"size": 902604,
"url": "http:\/\/example.org\/files\/picture1.jpg",
"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture1.jpg",
"deleteType": "DELETE"
},
{
"name": "picture2.jpg",
"size": 841946,
"url": "http:\/\/example.org\/files\/picture2.jpg",
"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/picture2.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture2.jpg",
"deleteType": "DELETE"
}
]}
I have no idea where to put this. Also I was trying to look inside the inspect tool to see what exactly its trying to send in the first place and I can't locate any json data at all being passed anywhere. Console is blank. I'm pretty new to javascript and json, so if anyone could please help I would appreciate!
<cffile action="uploadAll"
destination="C:/inetpub/ww
nameconflict="overwrite"
filefield="files"
result="uploadResult"/>
<cfoutput>#serializeJSON(u
When I look in firefox I see the information is there and appears to be correct but I was told it needs to be shown in the format below. Can anyone give me an example of code on how to take that coldfusion variable and somehow format it to be layed out like shown below?
I'm in way over my head on this one. I dont know how or where to go to get the result from the upload to have it transformed into what is shown below. No other information is provided and I'm in over my head on this one.
{"files": [
{
"name": "picture1.jpg",
"size": 902604,
"url": "http:\/\/example.org\/files\/picture1.jpg",
"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/picture1.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture1.jpg",
"deleteType": "DELETE"
},
{
"name": "picture2.jpg",
"size": 841946,
"url": "http:\/\/example.org\/files\/picture2.jpg",
"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/picture2.jpg",
"deleteUrl": "http:\/\/example.org\/files\/picture2.jpg",
"deleteType": "DELETE"
}
]}
I have no idea where to put this. Also I was trying to look inside the inspect tool to see what exactly its trying to send in the first place and I can't locate any json data at all being passed anywhere. Console is blank. I'm pretty new to javascript and json, so if anyone could please help I would appreciate!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the fast help on the syntax!
You could use cflocation to redirect. However, you can't do both, ie return JSON and redirect on the same page.
ASKER
Do you know how I can make it redirect to a different page after all the files are uploaded?