Why the server is not responding?

Would like ajax to make the game wrote the code and he didn't answer.
Here is the js:
<!DOCTYPE html>
<html>
the <head>
<title>Game</title>
</head>
the <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);
 } 
}
//PSTS
setInterval(draw,20);
</script>
</body>
</html>

Here is the php:
<?php
$inp = $_POST['ourForm_inp'];

echo 'LOL';
April 19th 20 at 12:19
1 answer
April 19th 20 at 12:21
Solution
and the request goes away, if so, what does he say?
Anything goes and says standards as if code 200 - hester_Seng commented on April 19th 20 at 12:24
I think all it returns you have an error

if(xhr.readyState == 4 && xhr.readyState == 200){
 text = xhr.responseText;
}

need

if(xhr.readyState == 4 && xhr.status== 200){
 text = xhr.responseText;
}

in General, most console ) - Alexzander_Berni commented on April 19th 20 at 12:27
@Alexzander_Berni, Thank You - hester_Seng commented on April 19th 20 at 12:30
@Alexzander_Berni, Could write again on what to replace the POST - hester_Seng commented on April 19th 20 at 12:33

Find more questions by tags JavaScript