@Afafks123132132165

Почему сервер не отвечает?

Хотел на ajax сделать игру написал код ,а он не отвечает.
Вот 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:
<?php
$inp = $_POST['ourForm_inp'];

echo 'LOL';
  • Вопрос задан
  • 64 просмотра
Решения вопроса 1
rasschitai
@rasschitai
Калькуляторы онлайн
а запрос уходит, если да, то что говорит?
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы