简体   繁体   中英

Problems with NaN when use jsonData and count variable

The Problem:

问题

When I try to concat in .html(jsondatareg.recibido+i) my explorer returns NaN value because the Js can't concat the two "strings" values.

My code:

var params = '&cedula='+cedula;
$.post('classes/recibirDatos', params, function(jsondatareg){
    for(var i = 0; i < jsondatareg.contador; i++){
        $('#recibido'+i).html(jsondatareg.recibido+i);
        console.log(jsondatareg.recibido+i);
    }
},'json');

The values:

价值

you can access the json property like an array , try this :

var params = '&cedula='+cedula;

$.post('classes/recibirDatos', params, function(jsondatareg){

    for(var i = 0; i < jsondatareg.contador; i++){
        $('#recibido'+i).html(jsondatareg["recibido" + i]);

        console.log(jsondatareg["recibido" + i]);
    }

},'json');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM