• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Can I pass complex data using wddx via a URL?

Community Beginner ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

I would like to pass complex structures via the URL. I know this can be done using hidden fields in forms but sometimes, I need to pass data from a file that is not a form. I'm having problems getting this to work. I have a really simple file that sets up a structure, serializes it using wddx and then attempts to pass the serialized structure from a hyperlink. The file that is called de-serializes the structure and tries to access it. I'm getting an error:

WDDX packet parse error at line -1, column -1. Premature end of file..
on the de-serialization line. I know that things are serialized/de-serialized correctly because if I serialize and then deserialize in the same file (without passing it to another file via URL), I can access it fine.

Is it possible to send WDDX packets to another cfm file via the URL?

Here is my simplified code:


dsp_testPage.cfm
-------------------------

<cfset relatives=StructNew()>
<cfset relatives.field1 = "Dad">
<cfset relatives.field2 = "Mom">
<cfset relatives.field3 = "Sister">
<cfset relatives.field4 = "Brother">


<cfwddx action="cfml2wddx" input="#relatives#" output="wddxRelatives">

<br>
<a href="./index.cfm?fuseaction=test&relatives=#wddxRelatives#">Click Here</a>
--------------------------------------------------------------------------------------------------------------------

Then I have another page called index.cfm (I'm using fusebox) that looks like this:

<html>
<head></head>
<body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">

<cfparam name="attributes.fuseaction" default="home">
<cfswitch expression="#attributes.fuseaction#">
<cfcase value="home">
<cfinclude template="./dsp_DISPLAY/dsp_TESTPage.cfm">
</cfcase>
<cfcase value="test">
<cfwddx input="#attributes.relatives#" action="WDDX2CFML" output="localAppData">
<cfoutput>
<br>Inside Test<br><br>
field1 = #localAppData.field1#<br>
field2 = #localAppData.field2#<br>
field3 = #localAppData.field3#<br>
field4 = #localAppData.field4#<br>
</cfoutput>
</cfcase>
</cfswitch>
</body>
</html>
TOPICS
Advanced techniques

Views

696

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Aug 28, 2007 Aug 28, 2007
Really silly mistake. In the file where I create the href link, I need to place this inside a <cfoutput> tag in order for the variable to be passed on the URL. It is working fine now that I hadded the <cfoutput>.

I will continue to investigate JSON but I really need my app to be independent of Javascript (able to work when Javascript is turned off) so it may not be the best option for me.

Thank You.

Votes

Translate

Translate
Guide ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

If you want to keep using WDDX, you must encode the GET string using the URLEncodedFormat function. i.e.
<a href="./index.cfm?fuseaction=test&relatives=#URLEncodedFormat(wddxRelatives)#">
Click Here</a>

I would investigate using JSON instead seeing as it is a lot less characters to send in a URL GET string. WDDX will make the string grow very fast.
If you want JSON and are on CFMX7, search for the CFJSON class. If you're on CFMX8, just use the SerializeJSON function.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

I added the URLEncodedFormat and a corresponding URLDecode but I still get the error

WDDX packet parse error at line -1, column -1. Premature end of file..

I will also look into JSON.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

I would honestly go with JSON instead.

To dig further into the WDDX, on the receiving end just prior to the WDDX2CFML - try outputting the WDDX string with CFOUTPUT and the HTMLCodeFormat function so that you can read it. Make sure the WDDX packet starts with something of the like:
<wddxPacket version='1.0'><header/><data>

and ends with something of the like:
</data></wddxPacket>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

Really silly mistake. In the file where I create the href link, I need to place this inside a <cfoutput> tag in order for the variable to be passed on the URL. It is working fine now that I hadded the <cfoutput>.

I will continue to investigate JSON but I really need my app to be independent of Javascript (able to work when Javascript is turned off) so it may not be the best option for me.

Thank You.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

I still think JSON is a multitude more optimal for what you are trying to accomplish. It's a much more optimized (from a number of characters standpoint) serialization method than WDDX which is bloat in my opinion. It really has little to do with Javascript to be honest - and as it is implemented in Coldfusion it is just a way to serialize, that is all. No dependence on Javascript at all.

Good to hear it's working!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

If the user is not required to have Javascript turned on in their browser, then I can use it. I'm going to get what I have working with wddx but I will definitely explore JSON.

Thanks!!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 28, 2007 Aug 28, 2007

Copy link to clipboard

Copied

LATEST
You missed the point, you can serialize Colfdusion Data in JSON without any Javascript. This means that if the user is using a javascript disabled web browser, it will still work. All the JSON serialization, as well as WDDX serialization happens on the server side.
Here's a CFJSON class I've used:
http://www.epiphantastic.com/cfjson/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation