Ajax Post Value on CF Side

1 view
Skip to first unread message

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 11:55:53 AM4/7/15
to ColdFusion Technical Talk

I'm sending an Ajax post to a CF page. The post data looks like (below) in
the counsel:



Object {name: "rid", value: "1"}



How in the heck to I get that value on the ColdFusion page?





Robert Harrison
Full Stack Developer
AIMG
<mailto:rhar...@aimg.com> rhar...@aimg.com
Main Office: 704-321-1234 ext.118
Direct Line: 516-302-4345
<http://www.aimg.com/> www.aimg.com









~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360413

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 12:04:21 PM4/7/15
to ColdFusion Technical Talk

Looks like a basic JSON value. Just parse it and you should have it put
into a variable.

or am I not understanding the question? I have yet to have my morning
coffee.
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360414

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 12:05:28 PM4/7/15
to ColdFusion Technical Talk

With JQuery:

var post_data = $('#myform').serializeArray();

$.post('/mycfpage',post_data,function(data){
//do stuff with JSON data here
var name = data.name;
var value = data.value;

//then manipulate the DOM from there

},'json');
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360415

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 12:28:25 PM4/7/15
to ColdFusion Technical Talk

You can very easily convert it to a structure using the deserializeJSON
function in CF. Here is a link with some examples of working with JSON in
ColdFusion. http://www.learncfinaweek.com/week1/JSON/
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360418

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 12:31:35 PM4/7/15
to ColdFusion Technical Talk

Let me make this simpler. The value being send via an ajax post is:

Object {name: "rid", value: "1"}

If I just want to dump that value/object how to I do it? I have no idea
what name CF see that as.

Robert Harrison
Full Stack Developer
AIMG
www.aimg.com



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360419

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 12:38:14 PM4/7/15
to ColdFusion Technical Talk

Once you convert it into a CF structure using deserializeJSON, you can then
use cfdump to see how CF interprets it.

On Tue, Apr 7, 2015 at 12:31 PM Robert Harrison <rhar...@aimg.com> wrote:

>
> Let me make this simpler. The value being send via an ajax post is:
>
> Object {name: "rid", value: "1"}
>
> If I just want to dump that value/object how to I do it? I have no idea
> what name CF see that as.
>
> Robert Harrison
> Full Stack Developer
> AIMG
> rhar...@aimg.com
> Main Office: 704-321-1234 ext.118
> Direct Line: 516-302-4345
> www.aimg.com
>
>
>
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360420

hofar...@houseoffusion.com

unread,
Apr 7, 2015, 1:09:31 PM4/7/15
to ColdFusion Technical Talk

Solved. The problem was I was overcomplicating this and treating it like
JSON just like everyone else has been advising.

With an AJAX post, the string: Object {name: "rid", value: "1"}

Appears to Coldfusion as form values. The values #form.name# and
#form.value# give me "rid" and "1".

Too simple, so it confused me.


Robert Harrison
Full Stack Developer
AIMG
rhar...@aimg.com
Main Office: 704-321-1234  ext.118
Direct Line: 516-302-4345
www.aimg.com




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:360421
Reply all
Reply to author
Forward
0 new messages