How do change headers when returning json in Coldfusion?
I'm running an query and getting the following JSON back:
{
"COLUMNS":["ID","TAGNAME"],
"DATA":[[11,"gard"],[61,"garden"]]
}
The problem is I'm using a plugin (found here http://www.devbridge.com/projects/autocomplete/jquery/#howto ) that only accepts data in the following format:
{
query:'...',
suggestions:['...','...'],
data:['...','...']
}
And so I get this error every time I call the data:
a.suggestions is undefined
[Break on this erro开发者_如何学JAVAr] (function(d){function l(b,a,c){a="("+c...h-a[a.length-1].length)+b}}})(jQuery);
If you have a need to custom format the response from ColdFusion, it is probably best to just write it out directly using cfoutput rather than trying to have another library massage it into working.
<cfoutput>
{
"query" : "#url.query#",
"suggestions" : [
<cfloop query="qryTags">
"#qryTags.tagname#",
</cfloop>
],
"data" : [
<cfloop query="qryTags">
"#qryTags.id#",
</cfloop>
]
}
</cfoutput>
Warning: it is unwise to simply regurgitate the url.query value directly into your JSON. That could lead to an attack on your website, it would be best to sanitize that value to ensure it can be cleanly encapsulated in your JSON string prior to sending it to the client. It is shown here simply for brevity in answering your real question.
精彩评论