Okay… the purpose of this is to run a script that sets a user to “online” and then gets all the other usernames that are also set to online. This problem is focused around AJAX (i think), as i cant seem to get the function to even activate to start the process.
main control file:
[CODE]<?php
$username=$_GET[n];
?>
<html>
<head>
<script src=”onlineupdate.js” type=”text/javascript”>
</script>
<script type=”text/javascript”>
function doupdate()
{
var v= ‘<?=$username;?>’;
setTimeout(“getonline(‘<?=$username;?>’)”,50);
setTimeout(“doupdate()”,800);
}
setTimeout(“doupdate()”,100);
</script>
</head>
<p>
<div id=”showonline”><b>List is loading…</b></div>
</p>
<body bgcolor=”#000000″>
</body>
</html>
onlineupdate.js:
[CODE]var xmlHttp
function getonline(str)
{
alert(“Loaded script”);
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert (“Browser does not support HTTP Request”)
return
}
var mytime= &ms=+new Date().getTime();
var url=”online.php?n=”+str+mytime ;
xmlHttp.open(“GET”,url,true);
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState==”complete”)
{
document.getElementById(“showonline”).innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp = null;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch (e)
{
if ( !GetXmlHttpObject.failedDetection )
{
alert(“Your browser does not support AJAX.”);
GetXmlHttpObject.failedDetection = true;
}
}
}
}
return xmlHttp;
}
GetXmlHttpObject.failedDetection = false;
The above javascript takes the argument, and ads it to the url, so that the target knows the username to keep setting “online”. As it is right now, the alert statement at the top of the script saying “Loaded script” isn’t even working…which lets me know that this function is not being executed from the main page.
online.php:
[CODE]<?php
include “connect.php”;
$username=$_GET[n];
$setonline=mysql_query(“UPDATE usercodes SET usonline=1 WHERE username=’$username'”) or die(mysql_error());
$getmsg2=mysql_query(“SELECT username from usercodes where usonline=1″) or die(mysql_error());
while($getmsg3=mysql_fetch_array($getmsg2))
{
if ($getmsg3[name]==”stargateanubis14”)
{
print “<font color=’green’><b>$getmsg3[name]</b></font>”;
}
else
{
print “<font color=’red’><b>$getmsg3[name]</b></font>”;
}
}
?>
<br>
<br>
<br>
<body bgcolor=#000000>
The above php code simply takes the user’s name from the url, sets that user to “online”, and then prints out all the users who are online too.
When i view the source, it shows the function having the correct username in place, but the function just wont activate.
I even attempted to run it without the variable/argument, and it didnt work.
I hate making people proof read like this…but i cant figure this out.
I am fairly new to AJAX in general, so any help or ideas are gratefully accepted!