Sending Arrays from javascript to ColdFusion and Railo - The diferences
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:
If you want to make one small chnage to your code try this
ReplyDeletedata: JSON.stringify(dataToSend),
Not tested but it seems that you need this with jQuery.
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
DeleteFor this to work on ACF you need:
ReplyDeletedata: { 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.
For others reading this your cfc did not come through.
DeleteBlogger dropped the tags:
Deletecfdump var="#deserializeJson(arguments.dataArray)#"
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.
ReplyDeleteI 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.
This is what Railo did it worked event with the ,
Deletehttp://i50.tinypic.com/313rq02.png
That would mean a bug in ColdFusion then.
DeleteThere is a new setting in CF10 that can help with this:
ReplyDeletehttp://www.boyzoid.com/blog/index.cfm/2012/2/26/ColdFusion-10--Form-Fields-With-the-Same-Name
Paul you might be interested to know that Adobe have identified this bug based on this
ReplyDeletehttps://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.
Thats great, perhaps will will see this come out in one of the patches for CF10
Delete