Skip to content

Instantly share code, notes, and snippets.

@huguogang
Created February 20, 2013 00:35
Show Gist options
  • Save huguogang/4991655 to your computer and use it in GitHub Desktop.
Save huguogang/4991655 to your computer and use it in GitHub Desktop.
JSONP in Coldfusion
<!--- if present, indicates this is a JSONP crosssite invocation --->
<cfparam name="callback" type="string" default="">
<cfparam name="jsonp" type="string" default="">
<!--- your code, variable "result" will be the json data for caller --->
<cfif callback NEQ ''>
<!--- JSONP --->
<cfoutput>#callback#(#serializeJSON(result)#);</cfoutput>
<cfelseif jsonp NEQ ''>
<!--- JSONP --->
<cfoutput>#jsonp#(#serializeJSON(result)#);</cfoutput>
<cfelse>
<!--- the old way --->
<cfoutput>#serializeJSON(result)#</cfoutput>
</cfif>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment