0

have my json response as

{"data":[
{
"percentage":94.3,
"population":53193
}]
}

I'm trying to insert the data to span is

My Javascript

$.post("<?php echo $baseUrl . '/population'; ?>", function(data) {
                $('.percentage').text(parseFloat(data.percentage));
                $('.population').text(parseInt(data.population));
            }, 'JSON');

Im getting NaN How do i resolve this

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Matt
  • 31
  • 4
  • `data` doesn't have a `percentage` or `population` property. It's an **array** that has a single element in it, which is the object with those properties. – T.J. Crowder Mar 04 '22 at 09:07
  • Please only use relevant tags. This question has nothing to do with [tag:php]. – T.J. Crowder Mar 04 '22 at 09:08

0 Answers0