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

Coldfusion 2021 and JSON

New Here ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Hello all,

 

We recently upgraded to Coldfusion 2021 from a working Coldfusion 9.

 

One of the applicatons uses the jquery .ajax function and serializeJSOn in Coldfusion.  Under version 9, it all works well, and returns to the javascript an array with ROWCOUNT, COLUMNS, and DATA.  

 

Under 2021, it does not work properly.  After some research, I have changed the #SerializeJSON(goat, true)# to #SerializeJSON(goat, "Struct" )#, and tried other various things.  

 

Interestingly, the 2021 javascript is not even fired under the "success" option in .ajax.  

 

Could anyone point me in the right direction?

 

Thanks,

 

Jim

Views

410

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 Expert ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Yes. First, in the CFML code doing that serializejson, have you done some diagnostics to output THERE what the results are, such as with a cfdump? And compare that output with what you get when running the same in CF9? (Do you still have the CF9 to test things? That would help a lot.)

 

Second, when you call the page the way the ajax would, what is the result you see (I mean WITHOUT it doing the cfdump)?

 

Finally, what do you see within the browser developer tools when the js code makes the jq/ajax call? You can see there in the "network" tab both the request and response. Similarly, does the "console" tab show any js error? (Indeed, does the network tab show that all the requests within the page got 200 return codes?)

 

There may well be some change between CF9 and 2021 that explains what you're seeing, and there may be a change we could suggest. Someone may well even offer one without any additional diagnostics. But assuming they don't, I offer the ideas above to help us help you.


/Charlie (troubleshooter, carehart.org)

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 ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Hello Charlie,

 

First off, thanks for the reply.  It often helps to talk things through.

 

Yes, I tried cfdumping it, but did not get any output 😞  Interestingly, even if I do a Hello<cfabort> and the top of the script, I still see nothing.  I do still have version 9 though 🙂

 

I am not sure what you mean by calling if the way ajax does.  But, if it runs through ajax, I see that the ajax calles the error option (instead of the success), and there appears to be a "<" in the output.  I was thinking that it would mean there is a rouge "<" somewhere, but I swear there is not!  Or, perhaps the serializejson was somehow adding it.  That is the nearest thing I can figure.  Also, interestingly, the database does not find a row, which is false.  There IS a row.  That is where it would be nice if I could cfabort in the script and show something, but it does not show a thing.

 

In the network tab, it shows the 200 return code, no javascript errors, but the response is that "<".

 

I appreciate you thinking about this for me.  I am at the end of my rope 🙂

 

Jim

 

 

 

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 ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

Hello,

 

Thanks for replying Charlie, I do appreciate it.  It sometimes helps to "talk" out loud.

 

First off, I did not have any luck <cdumping> anything.  I even tried a simple hello<cfabort> at the top of the script, but it all seems to be ignored.

 

As I continue to look around, I noticed that the ajax "error" is where it is going to, instead of the "success".  I also noticed, looking at chrome developer tools, that the response from the server seemed to have an "<" at the start of the row.  I do not see any rougue "<", and the exact same code works on version 9, in fact, it works perfectly fine.  If I, in the error section replace the "<" with "", and then do a json.parse on it, the info comes up as I expect.  That is leading me to believe that it is in the serializejson.   

 

Thanks again,

 

Jim

 

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 Expert ,
Jan 16, 2023 Jan 16, 2023

Copy link to clipboard

Copied

LATEST

@Jim2560103530pd , the ColdFusion 9 serializeJson functionality is still there. Subsequent versions of ColdFusion simply added more attributes.

 

SerializeJson currently has at least 3 queryFormats: row, column and struct. It seems from your description that you want queryFormat=column. In any case, the following example should help you choose.

 

<cfscript>
goat = queryNew("id,name","integer,varchar", 
[ 
	{id=1,name="Goat1"}, 
	{id=2,name="Goat2"}, 
	{id=3,name="Goat3"} 
]); 

writeoutput("serializejson(goat,'row')=" & serializejson(goat, "row") & "<p>");
writeoutput("serializejson(goat,'column')=" & serializejson(goat, "column") & "<p>");
writeoutput("serializejson(goat,'struct')=" & serializejson(goat, "struct"));
</cfscript>

 

 

 

 

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