This question already has an answer here:
in php
<?php
$arr = array ('a'=>1,'b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr); // {"a":1,"b":2,"c":3,"d":4,"e":5}
?>
in javascript,
$.getJSON('drivetracker2.php', function(data) {
console.log(data);
});
I am trying to access the php array which was sent via json to javascript.
but it says data is undefined.
anyone know why and how to fix this problem?
</div>
Try this
$.post('drivetracker2.php', function(data) {
console.log(data);
},'json');
Add this just before you echo the json.
header('Content-Type: application/json');