Best way to pass params from php to javascript
Use json_encode, better than simple parameter replacement
e.g.
<script type="text/javascript">
var myObj = {};
myObj.config = <?php echo json_encode($my_config); ?>;
</script>
Then later in js you can call myObj.config.field1, where field1 is a array key passed from php
e.g.
<script type="text/javascript">
var myObj = {};
myObj.config = <?php echo json_encode($my_config); ?>;
</script>
Then later in js you can call myObj.config.field1, where field1 is a array key passed from php
Comments
Post a Comment