PDA

View Full Version : Anyone know whats wrong?



MrCraig
26-12-2007, 05:31 PM
Im trying out some AJAX to refresh the site stats on HabboSoft.com and so far i have


<script type="text/javascript">
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;

var http = createRequestObject();
}
function handleResponse() {
if(http.readyState==4)
{
response = http.responseText;
document.getElementById("sitestats").innerHTML = response;
}
}
function checkonline() {
http.open('get','online/index.php');
http.onreadystatechange = handleResponse;
http.send(null);
}
setInterval("checkonline()",30000);
</script>


However, it has an error icon and doesnt work at all..

Does anyone know how to fix?

Dentafrice,
26-12-2007, 05:34 PM
Download http://script.aculo.us/

Include it in your page,



<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js"></script>


Then:



<script type="text/javascript">

function update()
{
new Ajax.Updater('sitestats', 'online/index.php');
}

update();
setInterval("update()",30000)
</script>

MrCraig
26-12-2007, 05:41 PM
oooh ty caleb :)

Dentafrice,
26-12-2007, 05:46 PM
Its an easy way to do things, you can also do effects with it =] Etc.

Or




<script type="text/javascript">

function update(div, page)
{
new Ajax.Updater(div, page);
}
</script>

<div id="sitestats"></div>
<div id="information"></div>
<a href="#" onclick="update('sitestats', 'online/index.php');">Update Stats</a>
<a href="#" onclick="update('information', 'information/index.php');">Update Information DIV</a>


Just cool stuff :P

MrCraig
26-12-2007, 06:02 PM
Ty :)

Always known about scriptaculous just never known how to work it :)

Any good TUTs?

Dentafrice,
26-12-2007, 06:19 PM
Not really, its pretty easy to learn.

Read up on the Scriptaculous WIKI on their site :]

Want to hide these adverts? Register an account for free!