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 onrequ开发者_如何学Pythonestend.cfm
should be executed on ajax requests.
As in my case this is generating some header info like meta tags etc.
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 youronRequestStart()
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.
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.
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
精彩评论