user160820
user160820

Reputation: 15200

coldfusion onrequestend.cfm

Is there a way to make onrequestend.cfm call conditional. i.e if I call a template through ajax, I don't want that onrequestend.cfm should be executed on ajax requests.

As in my case this is generating some header info like meta tags etc.

Upvotes: 2

Views: 982

Answers (3)

crazy4mustang
crazy4mustang

Reputation: 165

We handle this with URL variables. Call any page with

?NoHeaderFooter=true

and then conditional logic in onRequestStart like this:

<cfif NOT StructKeyExists(URL,"NoHeaderFooter")>
output header/footer etc. here
</cfif>

Can be used in both onRequestStart and onRequestEnd or create two variables so you can control each. Then all our ajax calls submit to something like:

report/FormController.cfc?Method=DoSomething&NoHeaderFooter=true

Upvotes: 0

Adam Tuttle
Adam Tuttle

Reputation: 19804

You have a few options:

  • Place a blank onRequestEnd.cfm in the directory containing the AJAX services you're connecting to, as Daniel recommends.
  • Switch to Application.cfc and the onRequestEnd() event instead of onRequestEnd.cfm; and inside your onRequestStart() event method, tell ColdFusion not to do anything for the onRequestEnd event.

Since you didn't specify, I'll guess and say that your AJAX requests use a CFC, like so:

/foo/bar.cfc?method=getSomething&param=value

In which case, you can easily identify all requests being routed to a CFC like this:

function onRequestStart(targetPath){
    if (listLast(arguments.targetPath, ".") eq "cfc"){
        structDelete(this, "onRequestEnd");
    }
}

Note that the function is only deleted for the current request, so you don't have to worry about it not being there for future requests. It will be.

Upvotes: 5

Daniel Sellers
Daniel Sellers

Reputation: 750

There is not that I am aware of. However if you place all the templates you will be calling in a sub-directory and place a blank onRequestEnd.cfm in the sub-directory that should give you the same effect.

Upvotes: 0

Related Questions