We recently set up a new website on our server: Windows 2K8 R2/IIS7/ColdFusion8 Ent. A key query which works no problem locally now doesn’t work in production.
Using <cfcontent type="text/json"> in the cfc function below causes the browser to open a download dialog box when a template calls this function.
<cffunction name="getPolls" access="remote" returntype="any" hint="Gets Polls">
<cfargument name="poll_id" type="numeric" required="true">
<cfset var qPoll = 0>
<cfquery name="qPoll" datasource="#application.datasource#">
select * from polls where poll_id = #arguments.poll_id#
</cfquery>
<cfcontent type="text/json">
<cfreturn qPoll>
</cffunction>
Below is the jQuery code which calls the above function. When this code is run inside a template (test.cfm), the download dialog opens asking me to save the file test.cfm rather than actually browsing the template.
$(function(){
var poll_id = global_poll_id || 0;
var uniqueid = new Date().getTime();
$.getJSON("/cfcs/poll.cfc?method=getPolls&returnformat=json&queryformat=column&uniqueid=" + uniqueid, {"poll_id":poll_id}, function(res,code) {
alert(res.ROWCOUNT); // error here
})
})
If I remove the <cfcontent type="text/json"> from the function, the download dialog no longer appears; HOWEVER, the ajax callback doesn’t seem to fire and an error returns:
res is not defined
This was related to my application.cfc. I needed to completely remove the onRequest method to get it working.