I have to use some data from PHP to JavaScript. I am using JSON for that. I encode the array with PHP's json_encode function and then I want to decode it with JavaScript.
<?php
$data = array(
"..."=>"...",
.....
);
?>
<script>
var data = jQuery.parseJSON('<?php echo json_encode($data); ?>');
console.log(data);
</script>
The problem is sometimes produces errors in javascript console on parsing the JSON, most of times when $data contains HTML.
How can I print a json encoded code inside javascript, dinamically with PHP?
Thank you!
var data = <?php echo json_encode($data); ?>;