
Nice one, very interesting ;]
mmm, if you search on google for 30 seconds you will find a number of libs/tutorials.
Hey, sorry to bump a little, but would this be possible to load a page, showing how many users online (I have the .php with the code), then an ajax reload that reloads every 30 seconds?
I'm not going to be using this account anymore, after today!
Yup very easy.
youd want somthing along these lines
What the above will do is write the contentes of "stats.php" to a div by the name of "Mydiv" every 30 seconds.Code://Calls function every 30 seconds. (function takes time in miliseconds) setInterval(Getstats, 30000); //id of div to put stats in to var divname = "Mydiv"; var statpage ="stats.php"; function Getstats() { // Set up request varible try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) {} //send Request xmlhttp.onreadystatechange = function(){ //Check page is completed and there were no problems. if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) { //Write data returned to div document.getElementById(divname).innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET", statpage); xmlhttp.send(null); }
Stats.php just needs to change its contence so the stats are correct every time it is loaded, that will then be shown in the div.
You change the div being used or the page being loaded via the two varibles:
var divname = "Mydiv";
var statpage ="stats.php";
Again, i havent tested it works so there could be a problem in it, hopefuly theres not, but if there is feel free to ask for help with it.
Also it may be a good idea to add some headers in the php of the page stats are loaded from to stop the brower cacheing that page.
hope that helps
ps. if theres an error and it doesnt load, the script just wont right anything, as opposed to alerting theres a problem as with the page load scripts.
Last edited by Mentor; 21-04-2007 at 11:31 PM.
Ah man, you are awesome. I shall test now, thanks very much!
I'm not going to be using this account anymore, after today!
I think my mysql databases are down - what a bad time for that to happen eh? I'll have to wait untill they're back up to see if it works.
As it shows the User online: 1 but it doesnt update even when my friends on (but its not your code, its actually the stats script). So I will post here when its back up! =)
thanks again!
EDIT: its not my mysql databases, must be my code. hmm, ill fix it and post back thanks!
Last edited by UnderGROUND; 21-04-2007 at 11:57 PM.
I'm not going to be using this account anymore, after today!
I cant edit, so here we goooo. I fixed my script.
I have the div for where I want it to be show as <div name="online"></div> and the part in your code is: var divname = "online";
yet it doesn't work, I think im doing something wrongIt just displays 1 user online. and doesnt go up.
I'm not going to be using this account anymore, after today!
Sure, I have done ^^
I'm not going to be using this account anymore, after today!
Want to hide these adverts? Register an account for free!