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

Comments

Popular posts from this blog

deep dive into Material UI TextField built by mui

angular js protractor e2e cheatsheet

react-router v6.4+ loaders, actions, forms and more