Passing javascript array to coldfusion CFC via Json

后端 未结 2 1588
生来不讨喜
生来不讨喜 2021-01-14 07:47

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         


        
2条回答
  •  不思量自难忘°
    2021-01-14 08:06

    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');
            }
        });             
     }
    
    
        
    
        
            
            UPDATE CRC_CERTIDAO CC
               SET CC.ncdcrcstatus = 0
                 WHERE CC.NCDCRCCERTIDAO in 
        
            
        
        
        
            
            
            
    
    
    

提交回复
热议问题