– Common Function Library Project

serializeToJSONP(data, callback)

Last updated June 11, 2009


Steve Good

Version: 0 | Requires: CF8 | Library: UtilityLib

This method takes two arguments, the data to be serialized and the callback in which to wrap the data. It then serializes the data and wraps it with the callback in JSONP format. This allows javascript to make cross domain requests. I will extend my facade CFCs from a base CFC that contains this method so I can call it internally.

Return Values:
Returns a string.


<cfset foo = [1,2,9,20]>
<cfoutput>#serializeToJSONP(foo, "runit")#</cfoutput>


Name Description Required
data Data to be converted into JSON. Yes
callback The function call that will wrap the output. Yes

Full UDF Source:

 Serializes data to JSONP format for cross domain JSON requests.
 @param data      Data to be converted into JSON. (Required)
 @param callback      The function call that will wrap the output. (Required)
 @return Returns a string. 
 @author Steve Good ( 
 @version 0, June 11, 2009 
<cffunction name="serializeToJSONP" displayname="Serialize to JSONp" hint="Serializes supplied data in JSONp format" output="false" returntype="any">
    <cfargument name="data" displayName="data" type="any" hint="The data to serialize" required="true" />
    <cfargument name="callback" displayName="callback" type="string" hint="the jsonp callback to use" required="true" />
    var local = {};
    local.json = serializeJSON(;
    local.jsonp = arguments.callback & '(' & local.json & ')';
    <cfreturn local.jsonp />


Latest Additions

Raymond Camden added
November 04, 2017

Leigh added
May 11, 2016

Raymond Camden added
May 10, 2016

Kevin Cotton added
May 05, 2016

Raymond Camden added
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson