Created
April 29, 2014 15:42
-
-
Save LukasRos/11404051 to your computer and use it in GitHub Desktop.
Passing data from PHP to JS
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('key1' => '</script>', 'key2' => 'hello world'); | |
?> | |
<html> | |
<head> | |
<title>Test</title> | |
<script type="text/javascript"> | |
var data = <?php echo json_encode($data); ?>; | |
</script> | |
</head> | |
<body> | |
<h1>Test</h1> | |
<script type="text/javascript"> | |
alert(data['key1']); | |
alert(data['key2']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment