Tuesday, March 15, 2011

javascript array to coldfusion

I have an array i've create in Javascript. The end result comes out to element1,element2,,,element5,element6,,,element9.... etc

Once passed to coldfusion, it removes the null elements, I end up with element1,element2,element5,element6,element9

I need to maintain these spaces, any ideas? My problem may begin before this, to explain in more detail...

I have a form with 13 elements that are acting as a search/filter type function. I want to "post" with ajax, in essence, i'm using a button to call a jquery function and want to pass the fields to a Coldfusion page, then have the results passed back. The javascript array may not even be my best option.

Any ideas?

From stackoverflow
  • Are you deserializing the jS array into a list? CF ignores empty list fields using its built-in functions. This can be worked around by processing the text directly. Someone has already done this for you, fortunately. There are several functions at cflib.org, like:

    etc, etc, etc.

  • In exchanging data between javascript and coldfusion have a look at using JSON.

    http://www.json.org

    http://www.epiphantastic.com/cfjson/

  • Instead of using the CF ListToArray function, use the Java String methods to split the string into an array. This will maintain the empty list items.

    <cfset jsList = "item1,item2,,item4,item5,,item6">
    <cfset jsArray = jsList.split(",")>
    <cfdump var="#jsArray#">
    

0 comments:

Post a Comment