ColdFusion 9 and ajax calls

I’ve been using ajax and ColdFusion for a long time with great success. Just
recently, I have been working on a new site that is on CF9; I know I’m behind
the times!

For years now (at least it seems that long) I’ve simply been passing my
variables from JavaScript to my cfc’s without any alterations.

I set my cfajaxproxy, define the cfc and give it a jsclassname, e.g.

    <cfajaxproxy cfc="ajax.ajaxFile" jsclassname="ajaxJSClassName">

On my js page I instantiate the class:

    var myAjaxJSClassName = new ajaxJSClassName();

And call the function in the cfc something like this:

        curElem = $(this);
        curID = $(curElem).attr('id');
        results = myAjaxJSClassName.cfcFunctionName(curID);

Fine. Not a problem. All works wonderfully.

If you opened firebug you can see the params of the ajax call and there
would be something like: argumentCollection{“variable1″:”12345″,”variable2″:”67890”}

I moved the exact code over to a CF9 site and I kept getting “WDDX packet
parse error at line 1, column 1. Content is not allowed in prolog..”

I tried so many things it was unreal. Stripped things down to the bare
bones. Updated JQuery. Took it out of JQuery. You name it, I probably tried

So, back to the trusty firebug and I see that in the params the
argumentCollection was “51838EEB9C” no matter what I passed. I searched and
searched and couldn’t find anything related to this.

So, I’m now on the verge of removing the ajax functionality when I happen
across Raymond Camden’s site. It’s not exactly what I’m experiencing, but
it’s close enough!

So I change up my JavaScript to be:

        curElem = $(this);
        curID = $(curElem).attr('id');
        var mydata = {data:[curID ]};
        returnFormat:"plain"}, function(res) {

And wouldn’t you know – everything works fine now.

I’d like to know exactly why it wasn’t working in CF9. I presume that it has
something to do with converting the data to JSON, but try as I might to
convert it and put it back into my old code, I just can’t get it to work.

I’m sure that there are some smarter people out there than I that may well
be able to help me out. In the mean time any one else having such issues,
try not to bang your head against the wall for too long and embrace JQuery
even more. :)

UPDATE – 4/12/2013
So after another bout of hair pulling I came across some other articles.
Another Raymond Camden and also something from Andy Scott. The most helpful was the comments from the Raymond Camden article about caching of the scripts folder in the CFIDE folder.

I did a lot of things so I’m afraid I’m not completely sure which fixed it. But in the end I had a different copy of the cfide/scripts/ folder called scripts_901, and I changed Default ScriptSrc Directory in CF admin under settings. This seemed to resolve the issue. I then subsequently changed the name of the old scripts folder, and renamed the script_901 to be scripts, updated CF admin again so that everything looks like it was originally.

I hope this helps.

Categories: CMS, E-Commerce, Integration and Mobile Apps | Tags: | Bookmark the permalink.
James Wood

About James Wood

James is a programmer here at Matrix Group. He is affectionately known around the office as S.P.A.R.T.A.C.U.S. because he is an avid marathon runner. He is also a beer connoisseur. A little known fact about James is that he was a toxicologist before switching professions for a change of pace. His flexibility will prove to be a valuable quality, because he has a beautiful daughter who’s just headed into her tween years.