EasyCFM.COM ColdFusion Forums / Coding Help! / Post string without form?

   Reply to Discussion | New Discussion << previous || next >> 
Posted By Discussion Topic: Post string without form?

remove book mark from this topic Printer-friendly Version  send this discussion to a friend  new posts last

WolfShade
05-13-2013 @ 11:53 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: Apr 2013

Hello, everyone.


If I use AJaX to POST a string of JSON data without using a form, is it still inserted into the FORM scope, in ColdFusion?  How can I access the data?


Thank you,


^_^


^_^

cfSearchin
05-13-2013 @ 1:09 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

quote:

If I use AJaX to POST a string of JSON data without using a form, is it still inserted into the FORM scope, in ColdFusion?


A literal <form> is not required. Any form fields sent via POST should be placed in the FORM scope.

quote:

How can I access the data?


All depends on how you are construct the POST request. Can you post your code?

WolfShade
05-13-2013 @ 1:23 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: Apr 2013

That's kind of what I thought, but my POST data is not showing up in the FORM scope.

Here is my submitting code:


xhr = new XMLHttpRequest();
xhr.open("POST","/path/to/document.cfm",false);
xhr.setRequestHeader("Content-type","x-www-form-urlencoded");
xhr.setRequestHeader("Content-length",JSON.stringify(finalarray).length);
xhr.setRequestHeader("Connection","close");
xhr.send('thisData=' + JSON.stringify(finalarray));
var reportText = xhr.responseText;


^_^

cfSearchin
05-13-2013 @ 1:37 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

It looks like you might be sending it as the request "body"  - not as a "form field". Check it by dumping getHttpRequestData() on the target page.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c11.html

This message was edited by cfSearchin on 5-13-13 @ 1:38 PM

WolfShade
05-13-2013 @ 1:51 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: Apr 2013

I'm CFDUMPing the GetHttpRequestData(), and it's showing a simple struct.

CONTENT: Binary followed by a bunch of integers.

HEADERS: Everything looks right, but the length says 15.

METHOD: Post

PROTOCOL: HTTP/1.1

I would paste it, here, but I can't.  My dev system is isolated from the internet.  Ultra-tight security.

Is there anything specific in the GetHttpRequestData() that you would like to know?

Thank you,



^_^

cfSearchin
05-13-2013 @ 2:19 PM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

Do you see the values you are trying to send anywhere in the structure ie the "thisData" value? Check the "content" value,.


Also, did you try sending it as "form field".

This message was edited by cfSearchin on 5-13-13 @ 3:00 PM

WolfShade
05-14-2013 @ 5:33 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Member
Posts:
Joined: Apr 2013

Content is showing up as binary data, all digits.  Not the JSON I'm expecting.

How do I send it as a form field?

Thank you,

^_^

cfSearchin
05-14-2013 @ 8:00 AM
Reply
Edit
Profile
Send P.M.
My Gravatar!
Powered by Gravatar
Senior Member
Posts: 608
Joined: Feb 2008

quote:

Content is showing up as binary data, all digits.  Not the JSON I'm expecting.


Okay, but that is probably where the value is - you just need to decode it into a string. Then deserialize the JSON. From the docs:

"...To determine whether data is binary, use IsBinary(x.content). To convert data to a string value, if it can be displayed as a string, use ToString(x.content)."

quote:

How do I send it as a form field?


Depends on the implementation. But it is not hard. Just check the documentation.

This message was edited by cfSearchin on 5-14-13 @ 8:00 AM


Website Designed and Developed by Pablo Varando.