I am trying to get a PHP JSON variable in my JS function:
var json_obj = jQuery.parseJSON ( ' + <?php echo $latLongJson; ?> + ' );
The PHP code which is fetching me the latLongJson variable is :
<?php
$latLongJson = $dbUrl->getCoordinates($id);
print_r($latLongJson);
?>
I am able to print latLongJson variable using PHP. But console.log for json_obj says it is undefined.
JS Code
<script>
//<![CDATA[
var json_obj = jQuery.parseJSON ( ' + <?php echo $latLongJson; ?> + ' );
//var json_obj = 1;
//]]>
console.log(json_obj);
</script>
Generated JS Code:
//<![CDATA[
var json_obj = jQuery.parseJSON ( ' + + ' );
//]]>
console.log(json_obj);