admin管理员组文章数量:1026989
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="mit" />
<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.
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="mit" />
<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.
Share Improve this question asked Dec 27, 2011 at 12:47 lagranzottolagranzotto 3271 gold badge5 silver badges16 bronze badges2 Answers
Reset to default 5jQuery 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="mit" />
<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 pletely.
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="mit" />
<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.
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="mit" />
<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.
Share Improve this question asked Dec 27, 2011 at 12:47 lagranzottolagranzotto 3271 gold badge5 silver badges16 bronze badges2 Answers
Reset to default 5jQuery 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="mit" />
<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 pletely.
本文标签: ajaxPassing javascript array to coldfusion CFC via JsonStack Overflow
版权声明:本文标题:ajax - Passing javascript array to coldfusion CFC via Json - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745444578a2151044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论