Created
December 13, 2013 16:17
-
-
Save pherrymason/7946715 to your computer and use it in GitHub Desktop.
Store JSON in data attribute
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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