通过 Json 将 javascript 数组传递给 Coldfusion CFC
我使用此 javascript 捕获在 Flexigrid 中选中的所有复选框,并尝试将此行 id 数组发送到 CFC
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,
},
dataType: "json",
success: function(){
alert('YES');
},
error: function(){
alert('NO');
}
});
}
CFC 下面
<cffunction access="remote" name="removeCertidaoCRC" returntype="boolean">
<cfargument name="numSeqCertidao" type="array" 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>
,当我尝试运行此函数时,我的服务器回答传递给 removeCertidaoCRC 函数的 NUMSEQCERTIDAO 参数不是类型大批。
我最近刚刚进入的一个延迟项目已经没有选择了。
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 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,
},
dataType: "json",
success: function(){
alert('YES');
},
error: function(){
alert('NO');
}
});
}
CFC Below
<cffunction access="remote" name="removeCertidaoCRC" returntype="boolean">
<cfargument name="numSeqCertidao" type="array" 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>
when i try to run this function, my server answers that The NUMSEQCERTIDAO argument passed to the removeCertidaoCRC function is not of type array.
I'm running out of options on a delayed project in which i entered just recently.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
jQuery 会很好地发送分开的数组,如 numSeqCertidao[] = 'val1', numSeqCertidao[] = 'val2' ... 但 ColdFusion 处理得很糟糕,并且不会接受它并重建它作为一个数组。
您的 JavaScript 未发送 JSON 格式的数据,dataType 选项用于响应数据的格式。根据您的需求,我建议您将
numSeqCertidao
作为列表发送,为 CFC 方法的参数提供一种字符串类型,并保留其余部分不变,应该可以正常工作。稍微修改一下代码:
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:
您传递给 CFC 的是一个 Javascript 数组。它不是 ColdFusion 阵列。所以对于 CFC 来说它看起来像一个字符串。将类型更改为“字符串”或“任意”,或者完全省略它。
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.