I'm trying to call a cfc method via ajax by using jQuery's post() method, but I keep getting an error message saying "the xxx parameter to the yyy function is required but was not passed in". Here's my cfc function:
<cffunction name="updateAssessment" returntype="struct" returnformat="json" access="remote" hint="For ajax update of a single assessment record">
<cfargument name="data" type="JSON" required="true" hint="Data structure received from ajax call">
<cfset var incomingData = "" />
<cfset var qry = "" />
<cfset var resultset = {success:false,message:"invalid data"}>
<cfif IsJSON(arguments.data)>
<cfset incomingData = deserializeJSON(arguments.data) />
</cfif>
<cfreturn resultset />
</cffunction>
and here's the jQuery code calling it:
$('.ajaxSubmitBtn').on('click', function() {
//grab values from editable table cells...
var assessmentid = $.trim($(this).closest('tr').find('.ajaxSubmitBtn').val());
var source = $.trim($(this).closest('tr').find('.sourceTD').text());
var lname = $.trim($(this).closest('tr').find('.lnameTD').text());
var fname = $.trim($(this).closest('tr').find('.fnameTD').text());
var ssn = $.trim($(this).closest('tr').find('.ssnTD').text());
var assessdate = $.trim($(this).closest('tr').find('.assessdateTD').text());
var casehranum = $.trim($(this).closest('tr').find('.casehranumTD').text());
var dob = $.trim($(this).closest('tr').find('.dobTD').text());
//Put values in a JSON object...
var JSONPacket = {
"assessmentid":assessmentid,
"source":source,
"lname":lname,
"fname":fname,
"ssn":ssn,
"assessdate":assessdate,
"casehranum":casehranum,
"dob":dob
}
//call cfc function via ajax using post()
$.post("../../../cfc/starsImporter.cfc", {method: "updateAssessment", data: JSONPacket},
function(response) {
console.log(response);
},
"json");
});
I'm clearly passing the required argument to the cfc function with "data: JSONPacket", so not sure what the problem is.
I think you need to pass the parameters individually. The way it's written now, jQuery is passing the data struct as strings with keys like data[source]
$('.ajaxSubmitBtn').on('click', function() {
//grab values from editable table cells...
var assessmentid = $.trim($(this).closest('tr').find('.ajaxSubmitBtn').val());
var source = $.trim($(this).closest('tr').find('.sourceTD').text());
var lname = $.trim($(this).closest('tr').find('.lnameTD').text());
var fname = $.trim($(this).closest('tr').find('.fnameTD').text());
var ssn = $.trim($(this).closest('tr').find('.ssnTD').text());
var assessdate = $.trim($(this).closest('tr').find('.assessdateTD').text());
var casehranum = $.trim($(this).closest('tr').find('.casehranumTD').text());
var dob = $.trim($(this).closest('tr').find('.dobTD').text());
//Put values in a JSON object...
var JSONPacket = {
"method" : "updateAssessment",
"assessmentid":assessmentid,
"source":source,
"lname":lname,
"fname":fname,
"ssn":ssn,
"assessdate":assessdate,
"casehranum":casehranum,
"dob":dob
}
//call cfc function via ajax using post()
$.post("../../../cfc/starsImporter.cfc", JSONPacket,
function(response) {
console.log(response);
},
"json");
});
CFC
<cffunction name="updateAssessment" returntype="struct" returnformat="json" access="remote" hint="For ajax update of a single assessment record">
<cfargument name="assessmentid" type="string" required="true" />
<cfargument name="source" type="string" required="true" />
<cfargument name="lname" type="string" required="true" />
<cfargument name="fname" type="string" required="true" />
<cfargument name="ssn" type="string" required="true" />
<cfargument name="assessdate" type="string" required="true" />
<cfargument name="casehranum" type="string" required="true" />
<cfargument name="dob" type="string" required="true" />
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With