Solved

Coldfusion, jQuery, Ajax and adding cfsetting showdebugoutput="false" to the returned content.

Posted on 2011-03-09
9
523 Views
Last Modified: 2012-05-11
I was looking at Ray Camden's blog, and I found a cool little tidbit (he has sooo many).
Blocking ColdFusion Debugging for AJAX Requests

Can I do something similar with the attached code?  If so, how do I do it?  (by 'it', I mean, how do I apply <cfsetting showdebugoutput="false"> to the template loaded into the content area)

T.I.A. All!
The onClick event:
onclick="loadTemplate('<cfoutput>#request.thisModule#/templates/#request.thisTemplate#</cfoutput>','ajaxContainer',<cfoutput>#getEmailTemplates.layoutID#</cfoutput>), processTemplateChange('<cfoutput>#getEmailTemplates.layoutID#</cfoutput>');"

loadTemplate function:
function loadTemplate(templatePath,containerID,templateID) {
	$('#'+containerID).load(templatePath, function() {
		var cookies = document.cookie.split(";");
		for (var i = 0; i < cookies.length; i++) {
			var cookie = cookies[i];
			var eqPos = cookie.indexOf("=");
			var name = eqPos> -1 ? cookie.substr(0, eqPos) : cookie;
			document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT';
		}
	});

	$('#vignetteLibraries').load('<cfoutput>#request.url#</cfoutput>admin/emailBeta/uiElements/cfm/element.vignette.libraries.cfm',{'templateID': templateID}, function() {
	});
}

Open in new window

0
Comment
Question by:brianmfalls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 35085747
Why not just do it like he showed ie Enable it in OnRequestStart ?

<cffunction name="onRequestStart" returnType="boolean" output="false">

You could adapt it to key off of a URL variable too. Then you could selectively enable/disable debugging for any page by appending a parameter to the url

http://yoursite.com/somePage.cfm?enableDebugOutput=true

<cffunction name="onRequestStart" returnType="boolean" output="false">
	<cfargument name="thePage" type="string" required="true">
	<cfset var reqData = "">
		
	<!--- is it ajax --->
	<cfif structKeyExists(url, "enableDebugOutput")>
		<cfsetting showdebugoutput="false">
	</cfif>
			
	<cfreturn true>
</cffunction>

Open in new window

0
 
LVL 1

Author Comment

by:brianmfalls
ID: 35085837
Are you saying that all I have to do is add "enableDebugOutput=true" to my url string?  Really?  If it's that simple, that would be really cool!

Like so?
onclick="loadTemplate('<cfoutput>#request.thisModule#/templates/#request.thisTemplate#</cfoutput>?enableDebugOutput=true','ajaxContainer',<cfoutput>#getEmailTemplates.layoutID#</cfoutput>), processTemplateChange('<cfoutput>#getEmailTemplates.layoutID#</cfoutput>');"

I can't do it exactly as he did, since I am none of what I posted is in a cfc. The onclick is in an image tag, within a carousel that displays available templates.  The script is an included element in a custom framework.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35085971
Almost.  You also need to add the snippet above to your onRequestStart method too. But yeah, it should be that simple.
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 1

Author Comment

by:brianmfalls
ID: 35086130
Oh man.  I wasn't thinking about the applicaiton.cfc at all...  lol  Thanks aqx.

Two more quick questions on the snippet you posted.

Is the following argument passed by coldfusion by default, or do I need to specify it in each request?
<cfargument name="thePage" type="string" required="true">

What is the following var doing?
<cfset var reqData = "">
0
 
LVL 1

Author Comment

by:brianmfalls
ID: 35086172
Now that I think about it, neither are required.  I can see now that you just copied that off of Ray's site.  Thanks again aqx.  As always, your input is spot on.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35086174
It's passed by default.  So you don't have to do anything extra.

<cfset var reqData = "">

Actually you can get rid of that.  It *was* used in Ray's example to hold the getHttpRequestData(). But it's not needed in the new example.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35086200
Now that I think about it, neither are required.  

Actually the argument is required.  The OnRequestStart function *must* have a specific signature or it may not work at all.  So don't change anything about the cffunction name or it's arguments.

<cffunction name="onRequestStart" returnType="boolean" output="false">
	<cfargument name="thePage" type="string" required="true">
	<cfif structKeyExists(url, "enableDebugOutput")>
		<cfsetting showdebugoutput="false">
	</cfif>
	<cfreturn true>
</cffunction>

Open in new window

0
 
LVL 1

Author Comment

by:brianmfalls
ID: 35086226
True.  I was just getting to pull my foot out of my mouth when you were kind enough to do it for me.  :)
0
 
LVL 52

Expert Comment

by:_agx_
ID: 35086355
You're welcome. I remember learning that the frustrating way: never change the signature of Application.cfc methods ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question