我有一个 .ejs 文件并添加了一个画布。当我点击名为circle的html画布元素时,如何将值发送到nodejs?是否应该有一个与 fetch 一起使用的 POST 方法?
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<canvas id ="canvas" style="border: solid 5px blue";></canvas>
<script>
const canvas = document.getElementById("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 1000;
canvas.height = 800;
var circle = new Path2D();
circle.arc(250, 75, 50, 0, 2 * Math.PI);
ctx.fillStyle = "gray";
circle.closePath
ctx.fill(circle);
canvas.addEventListener('click', (event) => {
var circle_1 = ctx.isPointInPath(circle, event.offsetX, event.offsetY)
if (circle_1) {
//I want to send values from here
}
})
</script>
</body>
</html>