I have a page that is making an $.ajax call to a handler method in Coldbox. I've done this many times, but in this current project, more than once, if I dump the rc scope at the start of the handler, there's nothing in it other than my usual stuff I add elsewhere on each request.
What's even more weird is that if I don't interrupt the flow of execution it will go from the handler into the model and through the query and back out and return a SUCCESS, even though none of the required values are there. If I dump the arguments scope in the model, nothing is there either. This sounds like either a coldbox bug or a misconfiguration or something, but at this point I'll hope it's something I'm doing wrong.
So, first up, here's the AJAX call:
function deleteAgendaItem(agendaid, eventid) {
var data = {},
url = "<cfoutput>#event.buildLink('agenda.delete')#</cfoutput>";
data.eventid = eventid;
data.agendaid = agendaid;
var xhr = $.ajax({type: "post", data: data, url: url, async: false, dataType : "json", contentType: "application/json; charset=utf-8"});
return JSON.parse(xhr.responseText);
}
I've dumped my data structure to ensure the values are in there.
Here's the handler in coldbox:
<cffunction name="delete">
<cfargument name="event">
<cfargument name="rc">
<cfargument name="prc">
<cfscript>
param rc.agendaid = 0;
param rc.eventid = 0;
var modelObj = getModel('agenda');
var data = modelObj.delete(agendaid=rc.agendaid, eventid=rc.eventid, clientid=rc.userInfo.currentClientID);
event.renderData(format="json", data=SerializeJSON(data));
</cfscript>
</cffunction>
This is where stuff gets weird. If I dump rc, there's nothing in it other than my rc.userInfo.* stuff which is added in the prehandler (it's the contents of the user's cookie).
For completeness, here's the model:
<cffunction name="delete" output="false" access="public" returntype="struct">
<cfargument name="agendaid" type="numeric" required="yes">
<cfargument name="eventid" type="numeric" required="yes">
<cfargument name="clientid" type="numeric" required="yes">
<cfset var ret = StructNew()>
<cfset ret.success = true>
<cfquery datasource="#variables.dsn#">
update agenda
set active = 0
where agendaid = <cfqueryparam value="#arguments.agendaid#" cfsqltype="cf_sql_integer">
and eventid = <cfqueryparam value="#arguments.eventid#" cfsqltype="cf_sql_integer">
and clientid = <cfqueryparam value="#arguments.clientid#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn ret>
</cffunction>
Like I said earlier, if I let everything run, it will pass on through the model and return ret, which is success=true. No errors thrown. VERY weird. And if I dump arguments, there's nothing in it.
I've dumped both event.getHTTPContent() and getHttpRequestData() and they too are empty when it comes to the data I'm sending over.
I'm running on CF2016 on a Mac, but I've run the same code on a Windows server running Lucee and the same issue occurs. My Coldbox verion is v4.3.0.
Another thing worth mentioning... I've had this same problem with other calls in this project, with one difference... while I can't see any of the values being passed in (they too are blank), if I let it run through the model, IT WORKS FINE. I still can't dump them in the model either. That is beyond bizarre...note that while I do param the values going into the model, the fact that when I dump the arguments scope in the model and nothing appears is weird.
21 years doing ColdFusion and eight years doing Coldbox and this is the weirdest thing I've seen...
So... maybe another set of eyes will help. Am I doing something wrong? I must be. Thanks. :)