I'm trying to use canvas on a PHP page I created. The same script and code runs on HTML but when I change the extension to PHP and access it on localhost it fails. Here is my HTML:
<html>
<head>
<title>Test Canvas</title>
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Amatic+SC">
</head>
<body>
<canvas id="testcanvas" width="1000" height="1000"></canvas>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="canvas.js"></script>
</body>
And my script:
'use strict';
$(document).ready(function() {
var cnv = document.getElementById('testcanvas');
var ctx = cnv.getContext('2d');
ctx.moveTo(0,0);
ctx.lineTo(500,300);
ctx.stroke();
});
Is there any reason why this works with HTML and not with PHP?
In case you are wondering what this script should do...
'use strict';
$(document).ready(function() {
var cnv = document.getElementById('testcanvas');
var ctx = cnv.getContext('2d');
ctx.moveTo(0, 0);
ctx.lineTo(500, 300);
ctx.stroke();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<canvas id="testcanvas" width="1000" height="1000"></canvas>
</div>