Hey everyone i have a minecraft server and i have a website to go along with it, and what i am trying to do is have a server status light to change automatically when i run my game server and when i close it. i have two pictures to be displayed when the server is up and when it is down.
here is a clip of my code that is directly in the body tag and at the end is the divs i want it to fill in so it can read the external file and to change the img icon automatically:
Code:
<script type="text/javascript"> //Status Light
var ifOnline;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
ifOnline=new XMLHttpRequest();
} else {// code for IE6, IE5
ifOnline=new ActiveXObject("Microsoft.XMLHTTP");
}
ifOnline.open("GET","/MINECRAFT_SERVER/server_status.txt",false);
ifOnline.send();
var isitOnline=ifOnline.responseText;
if (isitOnline == "0") {
document.getElementById("testtest").innerHTML = "offline";
document.getElementById("Status_Light").src = "_img/red_light.png";
} else if (isitOnline == "1") {
document.getElementById("testtest").innerHTML = "online";
document.getElementById("Status_Light").src = "_img/green_light.png";
}
</script>
<div class="server_idtext">Server IP: cozzycraft.zapto.org</div>
<div class="server_status_light"><img id="Status_Light" src=""/></div>
<div id="testtest"></div>
i put your script in my webpage, but the js isnt modifying the img.src still.
what my problem is i have a .bat file to write a 1 or a 0 in a seperate txt file (server_status.txt) so the server would read online or offline. and what im trying to do with that file is use a simple script to read that file automatically and if ajax reads it as a 1 then it changes the img to a green light icon i have, and if it reads a 0 then it changes it to a red light icon.
i have learned to now put js at the end of the webpage for it to load everything before modifying it, its just im still having a lil trouble. =/
That script works on my server. It looks like you are not connecting to the txt file.
Change the ./MINECRAFT_SERVER/server_status.txt to /MINECRAFT_SERVER/server_status.txt and then to nothing ie; MINECRAFT_SERVER/server_status.txt
and it loads perfectly on my computer and ive tested it on other computers out of my home network. i just dont understand the problem now if it isnt the script.
Last edited by Cozzimoto; 01-16-2012 at 08:08 PM..
Windows 2008 \ IIS 7 doesn't have the axd handler mapping set up by default for using Ajax so you need to put the following code into your web.config file if you want to use Ajax and are on one of our Windows 2008 hosting plans.
im running windows 7 64 bit and i clipped it in on my index and i get a error 500 now. IIS is becoming more of a headache now =/
another thing i dont get why i would need to enable ajax is i already have two other elements running on the homepage that use ajax. i have a news feed in an xml file and i also have an alerts update in a seperate file as well that i use ajax to fetch
Last edited by Cozzimoto; 01-16-2012 at 08:42 PM..