Sending Arrays from javascript to ColdFusion and Railo - The diferences

by 8:43 AM 11 comments

Wile attempting to answer a question on Stack Overflow I ran into an interesting difference between Railo and ACF

I've begun to use Railo more and more and this simple piece of code I expected would "just work". Well on Railo it did. On ACF it did not.

ACF sees the js array passed as a variable names "array[]" ( literally ) with a comma separated string as the arguments. Railo sees this as an array server side and treats it as such. See the results. ( not I have a cfdump is the ajax call using fire bug I can see the result of the dump of the arguments scope )

Railo:



AFC:




CFC:


CFM:













Paul Kukiel

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

11 comments:

  1. If you want to make one small chnage to your code try this

    data: JSON.stringify(dataToSend),

    Not tested but it seems that you need this with jQuery.

    ReplyDelete
    Replies
    1. Yes that works, I posted the reply below before reading your last comment. Note that I ONLY tried this with jQuery it may well be different with EXTjs and it's axaj routines

      Delete
  2. For this to work on ACF you need:

    data: { dataArray: JSON.stringify(dataArray) },

    and in the cfc:



    Which sends across a simple array. In Railo this is handled for you.

    With Railo it just worked, with ACF there is an extra layer. Right or wrong.

    ReplyDelete
    Replies
    1. For others reading this your cfc did not come through.

      Delete
    2. Blogger dropped the tags:

      cfdump var="#deserializeJson(arguments.dataArray)#"

      Delete
  3. You're right, I sent you and email about it. The thing is I had to go back to the json specs to confirm it. It seems that Railo adheres to accepting the correct Json, where as ColdFusion requires it to be quoted. I guess using ColdFusion quirks for so long, one becomes a bit complacent to it.

    I can see where Adobe did what they did with ColdFusion, but if you were to enter the following in your example what would Railo do?

    Value 1: This is a test, or is it not
    Value 2: 256
    Value 3: interesting

    My guess is Railo will handle this correctly, where as ColdFusion must have all 3 quoted.

    ReplyDelete
    Replies
    1. This is what Railo did it worked event with the ,

      http://i50.tinypic.com/313rq02.png

      Delete
    2. That would mean a bug in ColdFusion then.

      Delete
  4. There is a new setting in CF10 that can help with this:
    http://www.boyzoid.com/blog/index.cfm/2012/2/26/ColdFusion-10--Form-Fields-With-the-Same-Name

    ReplyDelete
  5. Paul you might be interested to know that Adobe have identified this bug based on this

    https://bugbase.adobe.com/index.cfm?event=bug&id=3184291

    Which references this blog as an example of the bug, and will be fixed. I doubt it will be done fore previous versions as that doesn't seem to be the Adobe way.

    ReplyDelete
    Replies
    1. Thats great, perhaps will will see this come out in one of the patches for CF10

      Delete