How can you debug a coldfusion script that doesn't display HTML or run javascript?

I am using a JavaScript plugin to upload files to a ColdFusion application. It uses AJAX to communicate with the server and expects JSON to return. (pretty standard) I have two cfm scripts.

The first contains a form for the plugin.

The second handles the actual downloads, deletions, list of returned files, etc.

The second script returns JSON as plain text for the plugin process.

The second script does not display HTML and JSON sent back to the first script is fed directly to the js plugin.

Everything works perfectly. I got it for uploading files and returning file lists.

my problem: As the second script code gets more complex, it becomes much harder to debug.

It does not display code, so cfdump is useless.

I am shaking in the dark without error messages or other information to tell me why something is not working.

my limitations: The plugin is large and complex, and I do not want to mess with it if I do not need it. And I didn’t have to bother with it because it works fine, this is my cf code, which is the problem.

I also do not have access to the administration area for this project.

But I need to somehow register or debug this code.

my solutions: I do cfdump in the third file, but this is not an ideal solution, since I spend half my time coding and half the time I change cfdump's solution to meet new needs. And also to develop my cfdump logger to handle various situations. I don't want to reinvent the wheel by writing my own journal, but I just want to code. I got my administrator to install the AJAX logger, not realizing that it is designed to register JavaScript, not ColdFusion. So it does not work.

I know that people worked with ColdFusion for AJAX. I cannot be the only one who has this problem. Any help is appreciated.

+4
source share
4 answers

Do not forget the simple and powerful <cflog> . You can dump variables at any point in your code, and if you want to reset the structure, you can use serializeJSON(someStruct) to see the whole structure (or an object converted to a structure) in your logs. Combine this with the tail view in Eclipse / CFBuilder, and you have a stream of internal processing for your non-HTML code.

+3
source

If you are using Firefox, install Firebug on it. On the console tab, you can see the entire Ajax request, expand the request to the HTML tab. On the HTML tab, you can see the Html template created on the server page (your second script), and there you can also find the coldfusion error. Firebug is a great tool for working with Ajax, I hope this helps too.

+2
source

I would suggest using <cftry> and send an error message using <cfmail type="html" ...><cfdump ... to get an idea of ​​your script.

Example:

 <CFTRY> <CFSET thingsmightgowronghere &= "foo" /> <CFCATCH type="any"> <CFMAIL from=" debug@example.com " to=" you@yours.com " subject="#cfcatch.Message#" type="html"><CFDUMP var="#cfcatch#" /></CFMAIL> </CFCATCH> </CFTRY> 

Debugging with firebug would also be possible, but if you cfdump something and look at it in firebug, it is not so convenient to scan through css / js, which creates cfdump.

+1
source

I'm curious that cfdump is unavailable due to lack of html tags. I only created a page with this code:

 <cfsetting showdebugoutput="no"> <cfset foo = "bar"> <cfdump var="#foo#"> 

And when I looked at it, the word "bar" appeared in the browser.

+1
source

Source: https://habr.com/ru/post/1447106/


All Articles