garcon Posted February 17, 2010 Share Posted February 17, 2010 var xmlhttp; var xmlhttpTwit; //function gets an xmlhttp object function getXmlHttpObj() { if(window.XMLHttpRequest) { //IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if(window.ActiveXObject) { //IE5, IE6 return new ActiveXObject("Microsoft.XMLHTTP"); } //not supported return null; } function loadXmlHttpObj() { //get xmlhttp objects xmlhttp = getXmlHttpObj(); xmlhttpTwit = getXmlHttpObj(); if(xmlhttpTwit == null) { alert("XMLHTTP not supported. You need to upgrade your web browser, suckah."); return; } } //call this to update twitter status function getTwitter() { //set callback function xmlhttpTwit.onreadystatechange = updateTwitter; //open and send request var req = "get_twitter.php"; xmlhttpTwit.open("GET", req, true); xmlhttpTwit.send(null); //restart timer refreshTwitter(); } //calls getTwitter after timeDelay function refreshTwitter() { //60 seconds delay var timeDelay = 60000; setTimeout("getTwitter();", timeDelay); } function updateTwitter() { //if readyState is 4, then request is complete if(xmlhttpTwit.readyState == 4) { //write in new definition document.getElementById("twitterStatus").innerHTML = xmlhttpTwit.responseText; //call last fm update getLastfm(); } } //call this to update lastfm function getLastfm() { //set callback function xmlhttpTwit.onreadystatechange = updateLastfm; //open and send request var req = "get_lastfm.php"; xmlhttpTwit.open("GET", req, true); xmlhttpTwit.send(null); } function updateLastfm() { //if readyState is 4, then request is complete if(xmlhttpTwit.readyState == 4) { //write in new definition document.getElementById("lastfm").innerHTML = xmlhttpTwit.responseText; } } function changeContent(var page) { //loading bar document.getElementById("content").innerHTML = "<img src=\"images/main/loading.gif\" />"; //set callback function xmlhttp.onreadystatechange = updateContent; //open and send request var req = page + ".php"; xmlhttp.open("GET", req, true); xmlhttp.send(null); } function updateContent() { //if readyState is 4, then request is complete if(xmlhttp.readyState == 4) { //write in new definition document.getElementById("content").innerHTML = xmlhttp.responseText; } } If I comment out changeContent() and updateContent() then the Twitter and lastfm bits will work fine. With them in - nothing works! I've tried vice versa. Is there something I don't see going wrong? I'm lost! Cheers Quote Link to comment Share on other sites More sharing options...
garcon Posted February 17, 2010 Author Share Posted February 17, 2010 Oh man, you don't write 'var' in front of an argument in the function definition! 2 minutes more fiddling and I solved it. Sorry! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.