i use this javascript to capture all checkboxes checked in a flexigrid and try to send this array of row ids to an CFC
function removeCertidao(){
var all
jQuery will do a good job of sending the array separated like numSeqCertidao[] = 'val1', numSeqCertidao[] = 'val2' ...
but ColdFusion handles this badly and does not take this and rebuild it as an array.
Your JavaScript is not sending data in JSON format, the dataType option is for the format of the response data. For your needs I would suggest you send numSeqCertidao
as a list, give your CFC method's argument a type of string and leave the rest of it as is, should work fine.
Slightly amended code:
function removeCertidao(){
var allVals = [];
$("input[id='certidao']:checked").each(function() {
allVals.push($(this).val());
});
if (allVals.length == 0) {
alert('É necessário escolher ao menos uma certidão.');
return false;
} else {
alert(allVals);
}
$.ajax({
type: "post",
url: "../../CFC/CRC.cfc",
data: {
method: "removeCertidaoCRC",
numSeqCertidao: allVals.join(),
},
dataType: "json",
success: function(){
alert('YES');
},
error: function(){
alert('NO');
}
});
}
<cffunction access="remote" name="removeCertidaoCRC" returntype="boolean">
<cfargument name="numSeqCertidao" type="string" required="true">
<cftry>
<cftransaction>
<cfquery datasource="portalCompras">
UPDATE CRC_CERTIDAO CC
SET CC.ncdcrcstatus = 0
WHERE CC.NCDCRCCERTIDAO in <cfqueryparam value="#numSeqCertidao#"
cfsqltype="cf_sql_integer"
list="yes">
</cfquery>
</cftransaction>
<cftransaction action="commit" />
<cfreturn 0>
<cfcatch type="any">
<cftransaction action="rollback" />
<cfreturn #cfcatch.message#>
</cfcatch>
</cftry>
</cffunction>
What you're passing to the CFC is a Javascript array. It's not a ColdFusion array. So to the CFC it looks like a string. Change type to "string", or "any", or just omit it completely.