Ask a Jedi: Ajax-bound requests and onRequest

This post is more than 2 years old.

So this is definitely something I've covered more than once, but as the questions keep coming in, I'm going to keep blogging it. My real hope is that Adobe listens in here as I think this is something that really needs changing in ColdFusion. Anyway, the question, from Samer:

I found a wired case, if you use onRequest function in Application.cfc and use cfgrid with bind attribute, it always return empty query to the grid "Response is Empty" !!

Can you help?

This is a fairly simple problem. onRequest, if it exists, breaks all flash remoting and CFC calls (remote calls I mean). Make sure you understand that. It doesn't matter what you do in onRequest - the mere existence of the method will call Flash Remoting/CFC (Remote) operations fail. Period.

As I said, this is something I truly wish Adobe would just fix as all it does is trip people up.

There is a way around it. Sean Corfield has a nice little work around that involves adding the following code to your onRequestStart (not onRequest, but onRequestStart):

<cfif listlast(arguments.thePage,".") is "cfc"> <cfset StructDelete(this, "onRequest") /> <cfset StructDelete(variables,"onRequest")/> </cfif>
Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA