Quote:
Originally Posted by rogersnm
DOES ANYONE HAVE A WORKING EXAMPLE OF THIS?
|
ok, here is a VERY stripped down demo as a standalone file, just put it in your main forum folder (ex. "forum") and name it "ajax.php"
All it does is give you the current time on a 1 sec refresh. Not something particullarly useful as there are far better ways to do this, but hopefully it helps.
PHP Code:
<?php
require_once('global.php');
if($_POST['do']=="time")
{
echo date('h:i:s A');
exit;
}
else if($_POST['do']=="time24")
{
echo date('H:i:s');
exit;
}
else
{
echo"
<html>
<head>
<script type=\"text/javascript\" src=\"clientscript/vbulletin_global.js\"></script>
<script type=\"text/javascript\" src=\"clientscript/vbulletin_menu.js\"></script>
<script language='javascript'>
function starttimer()
{
loadurl();
timer=setTimeout(\"starttimer()\",1000); // Sets the time out in milliseconds, 1000 = 1 second
}
function stoptimer()
{
clearTimeout(timer);
}
function loadurl()
{
xmlhttp = new vB_AJAX_Handler(true);
xmlhttp.onreadystatechange(triggered);
xmlhttp.send('ajax.php', 'do=time');
// switch to 'do=time24' to change to 24 hour clock
}
function triggered()
{
if (xmlhttp.handler.readyState == 4 && xmlhttp.handler.status == 200 && xmlhttp.handler.responseText)
{
document.getElementById(\"output\").innerHTML = xmlhttp.handler.responseText;
// If you where adding to a page, as in a chat room you could try something along these lines
// document.getElementById(\"output\").innerHTML += \"<br>\" + xmlhttp.handler.responseText;
}
}
</script>
</head>
<body onload='starttimer()' onunload='stoptimer()'>
<div id='output'></div>
</body>
</html>
";
}
?>