ColdFusion serializeJSON example

I would like to see a simple example of a template with the publication of SerializeJSON and deserializeJSON on the same template and array, adding every time a skip occurs. I have tried this several times, and I am always confused with the transition.

+1
source share
1 answer
<cfif structKeyExists(form,"jsonArray")>
    <cfset arrayData = deserializeJSON(form.jsonArray) />
    <cfset arrayAppend(arrayData,form.theText) />
<cfelse>
    <cfset arrayData = [] />
</cfif>
<cfoutput>
    <form name="input" action="ableto.cfm" method="post">
        <input type="hidden" value='#serializeJSON(arrayData)#' name="jsonArray" id="jsonArray" />
        Text: <input type="text" value="" name="theText" id="theText" />
        <input type="submit" value="Subby" />
    </form>
</cfoutput>

<cfdump var="#arrayData#" />
<cfdump var="#form#" />
+3
source

All Articles