I'm having an issues with this script from my own debugging it appears that the readyState is doing the following
1 ... 4 ... 1 ... 4
the second time it appears not to have any response so I end up seeing my content shortly (if all my debugging alerts are on) but it then dissapears when the ready state jumps to 4 for the second time. I have a feeling there is something very simple that I'm missing but it's been a long week for me
//Begin AJAX
//Browser Support Code
function goToPage(loc)
{
var ajaxRequest;
try
{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
alert("ajaxRequest created!");
}
catch (e)
{
// Internet Explorer Browsers
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(loc)
{
if(ajaxRequest.readyState == 4)
{
if(ajaxRequest.status == 200 || ajaxRequest.status == 304)
{
document.getElementById('greenBox').innerHTML = ajaxRequest.responseText;
}
}
}
//contruct url
var url = "pageserver.php?loc=" + loc
ajaxRequest.open("GET", url, true);
ajaxRequest.send(null);
}
pageserver.php
<?php
//Begin frame
/*
if ($_GET['loc'] == "")
{
$textRight = "";
$textLeft = "";
echo encap($textRight, $textLeft);
}
*/
require_once("inc/dbinfo.inc");
if ($_GET['loc'] == "home")
{
$textRight = '##############################################';
$textLeft = '###############################################';
echo encap($textLeft, $textRight);
}
if ($_GET['loc'] == "register")
{
$textRight = '##############';
$textLeft = '################';
echo encap($textLeft, $textRight);
}
if ($_GET['loc'] == "browse")
{
$query = "######################";
$result = mysql_query($query);
for($i=0; $i > 10; $i++)
{
$array = mysql_fetch_assoc($result);
if ($i == 0)
{
$textRight = #########################;
$textLeft = ######################;
}
else if ($i > 0)
{
$textRight = #############################################;
$textLeft = ##############################################;
}
echo encap($textLeft, $textRight);
}
}
if ($_GET['loc'] == "about")
{
$textRight = '############################';
$textLeft = '#############################';
echo encap($textLeft, $textRight);
}
if ($_GET['loc'] == "bid")
{
if (!$_GET['id'])
{
//error
}
else if ($_GET['id'])
{
$id = $_GET['id'];
$query = "#########################";
$result = mysql_query($query);
$array = mysql_fetch_assoc($result);
}
echo encap($textLeft, $textRight);
}
function encap($textLeft, $textRight)
{
return ('<span id="leftBox" class="leftBox">'.$textLeft.'</span><span id="rightBox" class="rightBox">'.$textRight.'</span>');
}
?>