This is probably an easy question, but I haven't been able to find a complete and specific answer. I create a json object in php with json_encode(), now i just need to get that object in javascript and parse it out. I wanted to do it in the same script, but I can do it another way if need be.
How do i get at this object from javascript?
<?php
$stuff = array('a' => 1, 'b' => 2);
?>
<script type="text/javascript">
var stuff = <?php print json_encode($stuff); ?>;
alert(stuff.a); // 1
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With