Click to See Complete Forum and Search --> : [RESOLVED] javascript strikes back!


Beffic
05-24-2009, 03:14 PM
Okay so I have two div's that I am trying to get to automatically update. I can get the charinfo to update but not the stats div. It just keeps trying to load. So I am not very good with java script and can't find the problem... any help?

<?php
include("../connect.php");
include("head.php");
?>
<center><table class="content">
<tr><td><div id="inventory">
<h3>Inventory</h3>
<p>*Double click to Equip/Unequip<br>*Red=Equipped</p>
<?php include("inventory.php"); ?>
<hr>
<p>News: This game is in beta stage as you can see and everything is a bit basic. No worries. I am working on making the game much more better including graphics and such. Your Admin at Jez-Your Productions!</p>
</div></td><td>
<h3>Character Info.</h3>
<div id="charinfo" rows="25" cols="95" readonly></div><br><hr>
<div id="location">
<h3>Location</h3>

</div></td><td>
<h3>Stats</h3>
<div id="stats" rows="25" cols="95" readonly></div><br>
<hr>
<div id="navigate">
<form>
<select id="menu" onchange="go()">
<option>--Navigate--</option>
<option value="hospital.php">Hospital</option>
<option value="shrine.php">Shrine</option>
<option value="statpointdistributer.php">Stat Point Distributer</option>
<option>--Misc--</option>
<option value="Top/index.php">Top Players</option>
</select>
</form>
</div></td></tr>
</table>
<div id="fightframe"><iframe src="Fight/index.php" style="background-color: #AABBD7;" frameborder="0px" width="99%"></iframe></div>
<hr>
<table class="chat"><tr><td><?php include("Chat/index.php"); ?></td></tr></table>
</center>

<script type="text/javascript">

/* Settings you might want to define */
var waittime=500;

/* Internal Variables & Stuff */
document.getElementById("stats").innerHTML = "Getting stats information...";
document.getElementById("charinfo").innerHTML = "Getting chatacter information...";


var xmlhttp = false;
var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_load(url) {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("stats").innerHTML = xmlhttp.responseText;

zeit = new Date();
ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
intUpdate = setTimeout("ajax_load('stats.php?x=" + ms + "')", waittime)
}
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("charinfo").innerHTML = xmlhttp.responseText;

zeit = new Date();
ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
intUpdate = setTimeout("ajax_load('character.php?x=" + ms + "')", waittime)
}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}
var intUpdate = setTimeout("ajax_load('stats.php')", waittime);
var intUpdate = setTimeout("ajax_load('character.php')", waittime);
</script>

Beffic
05-25-2009, 05:44 PM
Okay I know you can get annoyed by BUMPS but still this is a problem blocking me from going any farther in work.

Anyone?

JPnyc
05-25-2009, 10:22 PM
I would start with renaming one of your date objects. I don't know that that's the problem, but it's generally a bad practice to reuse names anyway. Same goes for the other variable names.

Beffic
05-26-2009, 02:01 AM
So I took your advice and I changed the variables around. After some time of guess and check I won the battle! haha...

So here is what I have now. and if you have any ideas for me to clean this up or make it more reliable that would be great! Just send a message!

<?php
include("../connect.php");
include("head.php");
?>
<center><table class="content">
<tr><td><div id="inventory">
<h3>Inventory</h3>
<p>*Double click to Equip/Unequip<br>*Red=Equipped</p>
<?php include("inventory.php"); ?>
<hr>
<p>News: This game is in beta stage as you can see and everything is a bit basic. No worries. I am working on making the game much more better including graphics and such. Your Admin at Jez-Your Productions!</p>
</div></td><td>
<h3>Character Info.</h3>
<div id="charinfo" rows="25" cols="95" readonly></div><br><hr>
<div id="location">
<h3>Location</h3>

</div></td><td>
<h3>Stats</h3>
<div id="stats" rows="25" cols="95" readonly></div><br>
<hr>
<div id="navigate">
<form>
<select id="menu" onchange="go()">
<option>--Navigate--</option>
<option value="hospital.php">Hospital</option>
<option value="shrine.php">Shrine</option>
<option value="statpointdistributer.php">Stat Point Distributer</option>
<option>--Misc--</option>
<option value="Top/index.php">Top Players</option>
</select>
</form>
</div></td></tr>
</table>
<div id="fightframe"><iframe src="Fight/index.php" style="background-color: #AABBD7;" frameborder="0px" width="99%"></iframe></div>
<hr>
<table class="chat"><tr><td><?php include("Chat/index.php"); ?></td></tr></table>
</center>

<script type="text/javascript">
/* Externally loading Character information div */
/* Settings you might want to define */
var waittimer=500;

/* Internal Variables & Stuff */
document.getElementById("charinfo").innerHTML = "Getting chatacter information...";


var xmlhttp3 = false;
var xmlhttp4 = false;


/* Request for Reading the Chat Content */
function ajax_character(url) {
if(window.XMLHttpRequest){
xmlhttp3=new XMLHttpRequest();
if(xmlhttp3.overrideMimeType){
xmlhttp3.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp3=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp3=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp3) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}



xmlhttp3.onreadystatechange = function() {
if (xmlhttp3.readyState==4) {
document.getElementById("charinfo").innerHTML = xmlhttp3.responseText;

zeit1 = new Date();
ms1 = (zeit1.getHours() * 24 * 60 * 1000) + (zeit1.getMinutes() * 60 * 1000) + (zeit1.getSeconds() * 1000) + zeit1.getMilliseconds();
intUpdater = setTimeout("ajax_character('character.php?x=" + ms1 + "')", waittimer)
}
}

xmlhttp3.open('GET',url,true);
xmlhttp3.send(null);
}
var intUpdater = setTimeout("ajax_character('character.php')", waittimer);
</script>

<script type="text/javascript">
/* Externally loading stats div */
/* Settings you might want to define */
var waittimerr=500;

/* Internal Variables & Stuff */
document.getElementById("stats").innerHTML = "Getting stats information...";


var xmlhttp = false;
var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_stats(url) {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}



xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("stats").innerHTML = xmlhttp.responseText;

zeit2 = new Date();
ms2 = (zeit2.getHours() * 24 * 60 * 1000) + (zeit2.getMinutes() * 60 * 1000) + (zeit2.getSeconds() * 1000) + zeit2.getMilliseconds();
intUpdaterr = setTimeout("ajax_stats('stats.php?x=" + ms2 + "')", waittimerr)
}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}
var intUpdaterr = setTimeout("ajax_stats('stats.php')", waittimerr);
</script>

JPnyc
05-26-2009, 12:24 PM
If it works now and works well, I would be inclined to leave well enough alone.