Jump to content

Stops working when two functions added


garcon

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.