- #1
aheight
- 321
- 109
Hi,
I am having problems integrating HTML, Javascript and PHP. I am using the instructions at this website to transfer data from PHP to Javascript:
http://www.dyn-web.com/tutorials/php-js/scalar.php
and have set up the following simple code to simply transfer a PHP array to Javascript but I can't confirm it's working: the alert(jvar) command is not printing to the console. I'm not even sure I should name it *.html or *.php or if I should run it on the server or in the browser. I would like to learn how to transfer data between PHP and Javascript and was wondering if someone could help me. Thanks.
I am having problems integrating HTML, Javascript and PHP. I am using the instructions at this website to transfer data from PHP to Javascript:
http://www.dyn-web.com/tutorials/php-js/scalar.php
and have set up the following simple code to simply transfer a PHP array to Javascript but I can't confirm it's working: the alert(jvar) command is not printing to the console. I'm not even sure I should name it *.html or *.php or if I should run it on the server or in the browser. I would like to learn how to transfer data between PHP and Javascript and was wondering if someone could help me. Thanks.
HTML:
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div>Test of PHP to Javascript transfer</div>
<?php
$var1=array(1,2.5,0.0098);
var_dump($var1);
?>
<script type="text/javascript">
var jvar = <?php echo json_encode($var1) ?>;
alert(jvar);
</script>
</body>
</html>
Last edited: