Jump to content

Ajax


vytas
 Share

Recommended Posts

I need to take out info from txt file from my server but i can't get the info out of my file called coords.txt and i dont know what i am doing wrong any help would be appreciated.

xmlHttp1();function sendPlayerRequest() { xmlHttp.readystatechange = statechanged; xmlHttp.open("GET","./coords.txt",true); xmlHttp.send(null);}setInterval("sendPlayerRequest()", 2000);function statechanged(){ if (xmlHttp.readyState == 4) {  var players = xmlHttp.responseText;  alert(players); }}

function xmlHttp1() {try  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }catch (e)  {  // Internet Explorer  try    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }  catch (e)    {    try      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }    catch (e)      {      alert("Your browser does not support AJAX!");      return false;      }    }  }}

Link to comment
Share on other sites

You have to declare the variable outside the function to make it global:var xmlHttp;xmlHttp1();function sendPlayerRequest(){xmlHttp.readystatechange = statechanged;xmlHttp.open("GET","./coords.txt",true);xmlHttp.send(null);}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...