Accessing data posted from Ext JS/Sencha Touch in ColdFusion

Ext JS and Sencha Touch post data to the server via the HTTP Request Payload. In order to access this data from a ColdFusion Component, you need to use the following syntax:

<cfcomponent>
 <cffunction 
    name="saveData" 
    access="remote" 
    returntype="string" 
    returnformat="plain">

   <cfset var requestData = deserializeJson(
              toString(getHttpRequestData().content)
   )>
   <!--- data is now available as requestData.fieldName --->
   <cfreturn serializeJson({success=true})>
 </cffunction>
</cfcomponent>

Note that variables containing nulls will not be present in the requestData variable, so you might need to use isDefined to normalize the dataset:

<cfcomponent>
 <cffunction 
    name="saveData" 
    access="remote" 
    returntype="string" 
    returnformat="plain">

   <cfset var requestData = deserializeJson(
              toString(getHttpRequestData().content)
   )>

   <!--- normalize foo if null --->
   <cfif not isdefined("requestdata.foo")>
     <cfset requestdata.foo = "">
   </cfif>

   <!--- data is now available as requestData.fieldName --->

   <!--- return success=true as json --->
   <cfreturn serializeJson({success=true})>
 </cffunction>
</cfcomponent>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s