Error 'Invalid Reply from Server' when using AjaxCFC

Posted on June 5, 2008

I’m 2 weeks into my new job and I just started working on a project that requires Ajax. After using CFAjax for so long, I figured I’d give AjaxCFC a go. I’ve heard nothing but good things about it, but I’ve been bashing my head against the wall for a while with this error. Took me forever to find the real cause.

The problem

I’m trying to relate records between two SELECT menus. Easy enough, right? Well not so much. I’ve got the code setup to send the value of the selected option in MenuA to the server, the problem is that all I ever get back is “Invalid Reply from Server”. Firebug shows nothing but a blank Response in the Console tab.

The code I’m using is based on a post by Brian Rinaldi.

After Googling for quite a while, I found a post by Ryan Everhart (from last year) who was having the same problem.

The ACTUAL Problem

Rob Gonda responded with this bit on information:

Having an onRequest method in your Application.cfc is known to break Web Services, Flash Remoting, and Ajax Calls. It affects and but is not limited to AjaxCFC.

Having seen about 0.5% of the code here, I break open the Application.cfc. Lo and behold, onRequest() does a lot of . . . stuff.

The solution

Rob also had this to say:

There’s a workaround that requires you to add some code to your onRequestStart method, checking if the call is targetting a CFC and removing the onRequest method dynamically. (check if the file ends with a cfc and run structDelete(this,’onRequest’). This will only deleted it for the current request.”

So I added this:

Application.cfc

<cffunction name="onRequestStart">
  <!--- REQUIRED FOR AJAX CALLS --->
  <cfif listLast(cgi.CF_TEMPLATE_PATH, ".") is "cfc">
    <cfset structDelete(this,'onRequest') />
  </cfif>
</cffunction>

I’m still getting the error, but I’m also getting a response back from the server which looks to be a WDDX representation of my CFC’s definition.

I’m going to work on this for the rest of the afternoon and I’ll update once I figure out what’s happening. I’m sure it’s just that I’m unfamiliar with AjaxCFC. Any input would be appreciated.

If I can’t get AjaxCFC to work soon, I’m going to give CFAjaxProxy a go.

UPDATE: Later that same day

Turns out the onRequest() issue was bogging down a coworker who is working on some new Web Services. He started a week before I did, so we’re in the same boat with the existing code.

RESOLVED: The next morning

I’ve been testing this using EXACTLY the code from Brian’s post. Well, almost exactly. My CFC extends ajax.cfc, but . . .

I added my own init() method to that CFC.

insert pac man dying sound here

As soon as I removed the init() method, I started getting data back correctly and the 2nd select menu populates just fine.

So my questions now are:

  1. Can I use data injection to pass a data source to the CFC?
  2. Can AjaxCFC call a CFC that is in the application scope?
  3. How could I do this using JQuery alone?

Regarding that 3rd one, if someone could take Brian’s code and make a JQuery version of it, I’m sure it would help more people than just me.

About the Author
Adrian J. Moreno

Adrian is a CTO and solution architect specializing in software modernization. More information