I have a cakephp function that returns data in json format in the following way
$response = array($query_license,$query_estate,$result_license);
if ($this->request->is('ajax')) {
echo json_encode($response);
die();
}
Well to be able to recover the data I do the following
$.ajax({
type: 'GET',
async: true,
cache: false,
url: license,
dataType: 'json',
data:{id_user_license:id_user_license,id_evaluation:id_evaluation},
success: function (data){
$.each(data,function(i,s){
if(s[0].cantidad_pendiente === 0){
$("#message_license").html('<p>Usted no cuenta con licensias disponibles</p>');
$("#modal_report__footer").html('<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>');
}else if(s[0].estado === 3){
$("#message_license").html('<p>Usted cuenta con '+ s[0].cantidad_pendiente +'</p>');
$("#message_consumed").html('<p>Esta evaluacion ya consumio licencia</p>');
$("#modal_report__footer").html('<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button>');
}else{
$("#message_license").html('<p>Usted cuenta con '+ s.indexOf(3).cantidad_pendiente +'</p>');
$("#modal_report__footer").html('<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancelar</button> <button type="submit" class="btn btn-danger">Consumir</button>');
}
});
}
});
The problem is that when I retrieve the values to show them to the user it shows me undefined and verifying inside the console I see this
console.log(s[0].cantidad_pendiente);
5
undefined
to verify that data is arriving in the data object perform console.log(data);
and this is the result
for some reason it brings me the value and then it shows empty something I'm doing wrong or I have to change thanks for your help