Skip to content

Instantly share code, notes, and snippets.

@pherrymason
Created December 13, 2013 16:17
Show Gist options
  • Save pherrymason/7946715 to your computer and use it in GitHub Desktop.
Save pherrymason/7946715 to your computer and use it in GitHub Desktop.
Store JSON in data attribute
<?php
$data = array('id'=>1, 'name'=>'will');
echo '<div data-post="'.htmlentities( json_encode($data) ) . '">'.
"<script>
var obj = $('div').data('post');
</script>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment