Jump to content

Ajax


vytas

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...