tags:

views:

31

answers:

2

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.

A: 

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.

Daniel Sellers
Coul you not put some conditional logic in the onRequestEnd.cfm which would determine the ajax pages? I prefix my ajax templates with ajax_ I would imageine FindNoCase(cgi.script_name,'ajax_',1) might do the trick.
cfEngineers
+5  A: 

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.

Adam Tuttle