1

hi when im trying to use xhttp.send(); it keeps returning

net::ERR_EMPTY_RESPONSE

my code is like this. when the user tries to presses too fast it kicks him off of the page. is there a way to stop this?

document.domain = "bitcoinrpg.com";

function UsernameTaken(name) {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (name == "") {
    document.getElementById("UsernameTaken").innerHTML = "";
    return;
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("UsernameTaken").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "CheckUsername.php?q=" + name, true);
  xhttp.send();
}

function BattlePlayers() {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("BattleTable").innerHTML = this.responseText;
    }
  };
  xhttp.open("POST", "GetPlayers.php?", true);
  xhttp.send();
  PlayerInfo();
}

function PlayerInfo() {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("CharacterBar").innerHTML = this.responseText;
    }
  };
  xhttp.open("POST", "PlayerInfo.php?", true);
  xhttp.send();
}

function FightPlayer(enemyName) {
  var elements = document.getElementsByClassName("BattleButton");
  for (var i = 0; i < elements.length; i++) {
    elements[i].setAttribute("disabled", "disabled");
  }
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("battlestatus").innerHTML = this.responseText;
      BattlePlayers();
    }
  };
  xhttp.open("GET", "FightPlayer.php?enemyname=" + enemyName, true);
  xhttp.send();
}

function InventoryShow() {
  var xhttp;
  if (window.XMLHttpRequest) {
    xhttp = new XMLHttpRequest();
  } else {
    xhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("InventoryTable").innerHTML = this.responseText;
    }
  };
  xhttp.open("POST", "PlayerInventory.php?", true);
  xhttp.send();
}

I've tried messing about with just about every php.ini setting ive tried renaming each xhttp variable for each function every time it just returns the same. you can see what im meaning here

enter image description here

Barmar
  • 741,623
  • 53
  • 500
  • 612
GregHBushnell
  • 143
  • 12
  • You should probably call `PlayerInfo()` in the callback function from `BattlePlayers()`, so it doesn't try to update the player info until after the battle has completed. – Barmar Sep 27 '16 at 19:19
  • See http://stackoverflow.com/questions/22284111/php-jquery-ajax-call-throws-neterr-empty-response – Barmar Sep 27 '16 at 19:21
  • had a read of that but nothing really fits my problem. it even happens on just basic javascript function to show/hide divs – GregHBushnell Sep 27 '16 at 20:22
  • I don't see how you could be getting that error in functions that don't perform an AJAX request. I suspect the problem is on the server. Check your server log for errors. – Barmar Sep 27 '16 at 20:27
  • Ok got a couple of errors I'll sort them in the morning see if that fixes it. Thanks – GregHBushnell Sep 27 '16 at 21:11
  • @Barmar Fixed the errors and it still happens? could it be something to do with my host? im with godaddy – GregHBushnell Sep 28 '16 at 06:40

1 Answers1

0

For anyone experiencing the same thing and you are with GoDaddy for your hosting. you need to switch its a problem on there end and switching fixed it for me.

GregHBushnell
  • 143
  • 12