Answer the question
In order to leave comments, you need to log in
Why is the server not responding?
I wanted to make a game on ajax, I wrote the code, but it does not respond.
Here is js:
<!DOCTYPE html>
<html>
<head>
<title>Game</title>
</head>
<body>
<canvas id = "canvas" width="95" height="127"></canvas>
<style type="text/css">
#canvas{
border:1px solid black;
}
</style>
<script type="text/javascript">
document.getElementById("canvas");
var ctx = canvas.getContext("2d");
buttons = [];
buttons.push({x:0,y:32,num:1});
buttons.push({x:32,y:32,num:2});
buttons.push({x:64,y:32,num:3});
buttons.push({x:0,y:64,num:4});
buttons.push({x:32,y:64,num:5});
buttons.push({x:64,y:64,num:6});
buttons.push({x:0,y:96,num:7});
buttons.push({x:32,y:96,num:8});
buttons.push({x:64,y:96,num:"->"});
text = "!";
function send(){
var xhr = new XMLHttpRequest();
text = encodeURIComponent(text);
xhr.open("POST","form.php");
xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xhr.send("ourForm_inp=" + text);
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.readyState == 200){
text = xhr.responseText;
}
}
}
document.addEventListener("mousedown",function(e){
for(i in buttons){
if(e.pageX >= buttons[i].x && e.pageX <= buttons[i].x + 32){
if(e.pageY >= buttons[i].y && e.pageY <= buttons[i].y + 32){
if(buttons[i].num == "->"){
send();
}else{
text = text + buttons[i].num;
}
}
}
}
});
function draw(){
ctx.clearRect(0,0,128,96);
ctx.fillStyle = "blue";
ctx.fillRect(0,0,96,32);
ctx.font = "20px Serif";
ctx.fillStyle = "black";
ctx.fillText(text,0,25);
ctx.font = "10px Serif";
for(i in buttons){
ctx.fillStyle = "black";
ctx.fillRect(buttons[i].x,buttons[i].y,32,32);
ctx.fillStyle = "yellow";
ctx.fillText(buttons[i].num,buttons[i].x + 15,buttons[i].y + 15);
}
}
//ПСЦ
setInterval(draw,20);
</script>
</body>
</html>
<?php
$inp = $_POST['ourForm_inp'];
echo 'LOL';
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question