Reputation: 15200
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
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
Reputation: 19804
You have a few options:
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¶m=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
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