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
https://forums.phpfreaks.com/topic/192407-stops-working-when-two-functions-added/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.