Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-15-2012, 11:05 PM   PM User | #1
Cozzimoto
New to the CF scene

 
Join Date: Jan 2012
Location: Dallas, Tx
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Cozzimoto is an unknown quantity at this point
Unhappy Hey guys i need some help for my game server

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>
if anyone can help it would be much appriciated
Cozzimoto is offline   Reply With Quote
Old 01-16-2012, 04:59 PM   PM User | #2
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
You never said what your problem was.
These lines are wrong
Code:
ifOnline.open("GET","/MINECRAFT_SERVER/server_status.txt",false);
ifOnline.send();
S/B
Code:
ifOnline.open("GET","./MINECRAFT_SERVER/server_status.txt",true);
ifOnline.send('');
And Put the javascript after the page has loaded so the js can modify it.

This works:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>New document</title>
</head>
<body>
<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>

<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.onreadystatechange = function()
{
    if (ifOnline.readyState == 4) {
	    if (ifOnline.status == 200) {

		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";
			}
	    } else {
	        	alert('There was a problem with the request. '+ ifOnline.status);
	    	}
	}
}
ifOnline.open("GET","./MINECRAFT_SERVER/server_status.txt",true);
ifOnline.send('');
</script>
</body>
</html>
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
Cozzimoto (01-16-2012)
Old 01-16-2012, 07:08 PM   PM User | #3
Cozzimoto
New to the CF scene

 
Join Date: Jan 2012
Location: Dallas, Tx
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Cozzimoto is an unknown quantity at this point
Thank you for the reply.

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. =/
Cozzimoto is offline   Reply With Quote
Old 01-16-2012, 07:35 PM   PM User | #4
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
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 see if one of those works.
sunfighter is offline   Reply With Quote
Old 01-16-2012, 07:44 PM   PM User | #5
Cozzimoto
New to the CF scene

 
Join Date: Jan 2012
Location: Dallas, Tx
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Cozzimoto is an unknown quantity at this point
no same problem. does it help if i tell you im hosting on my own computer with IIS 7 and the host i am using is No-ip??

like is there maybe a setting in my server that is stopping me from what i wanna do.

this is the website address: http://cozzycraft.zapto.org/
and your test file you wrote for me is here: http://cozzycraft.zapto.org/test.html

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..
Cozzimoto is offline   Reply With Quote
Old 01-16-2012, 08:27 PM   PM User | #6
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,387
Thanks: 18
Thanked 350 Times in 349 Posts
sunfighter is on a distinguished road
I think your right. How could a large great grand really really trustworthy company like microsoft miss this?

I found this link http://ssysadmin.com/developers/enab...s7-server.html and this
Quote:
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.

<system.webServer>
<handlers>
<add name="Ajax" path="*.axd" verb="*" modules="IsapiModule"
scriptProcessor="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"
resourceType="Unspecified"
preCondition="classicMode,runtimeVersionv2.0,bitness32" />
</handlers>
</system.webServer>
on the internet.
sunfighter is offline   Reply With Quote
Users who have thanked sunfighter for this post:
Cozzimoto (01-16-2012)
Old 01-16-2012, 08:38 PM   PM User | #7
Cozzimoto
New to the CF scene

 
Join Date: Jan 2012
Location: Dallas, Tx
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
Cozzimoto is an unknown quantity at this point
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..
Cozzimoto is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, game, javascript, server

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:02 PM.


Advertisement
Log in to turn off these ads.