Jump to content

Buddy List Updater


shane18

Recommended Posts

	function BUDDY_UPDATE(){
xmlhttp2 = new XMLHttpRequest();
xmlhttp2.onreadystatechange = BUDDY_CHANGE;
function BUDDY_CHANGE(){
if(xmlhttp2.readyState == 4){
BUDDIES = xmlhttp2.responseText;
BUDDIES.split("#");
for(BUDDY8 in BUDDIES){
BUDDY8.split(",");
if(BUDDY8[1]){
document.getElementById(BUDDY8[0]).src="images/online.bmp";
}else{
document.getElementById(BUDDY8[0]).src="images/offline.bmp";
}
}
setTimeout(BUDDY_UPDATE(),4000);
}
}
    xmlhttp2.open("GET","update.php?ACTION=BUPDATE",true);
    xmlhttp2.send(null);
}

 

Does not work... no clue why... imma php programmer im new at javascript

 

...and yes i have <body onLoad="BUDDY_UPDATE();">

Link to comment
Share on other sites

	function BUDDY_CHANGE(){
if(xmlhttp2.readyState == 4){
BUDDIES = xmlhttp2.responseText;
BUDDIES.split("#");
for(BUDDY8 in BUDDIES){
BUDDY8.split(",");
if(BUDDY8[1]){
document.getElementById(BUDDY8[0]).src="images/online.bmp";
}else{
document.getElementById(BUDDY8[0]).src="images/offline.bmp";
}
}
setTimeout(BUDDY_UPDATE(),4000);
}
        }

function BUDDY_UPDATE(){
xmlhttp2 = new XMLHttpRequest();
xmlhttp2.onreadystatechange = BUDDY_CHANGE;
        xmlhttp2.open("GET","update.php?ACTION=BUPDATE",true);
        xmlhttp2.send(null);
}

 

Still does not work...

Link to comment
Share on other sites

You have a fatal error here:

 

Uncaught TypeError: Cannot set property 'src' of null

 


document.getElementById(BUDDYI[0]).src="images/offline.bmp";

 

It looks like your if is failing and BUDDYI[0] is null. I'd alert out the contents of your buddy array to make sure it is being properly populated/split

Link to comment
Share on other sites

This should be good for that chunk.. although it looks like u have more errors... like calling BUDDY_CHANGE; instead of BUDDY_CHANGE(); in BUDDY_UPDATE();...

 

anyway... this is untested..

 


var buddyString=xmlhttp2.responseText;
        var buddyArray=buddyString.split("#");
        
        for(buddy in buddyArray){
        
            var buddyOnline=buddyArray[buddy].split(',');
            
            if(buddyOnline[1]>0){// guessing 1 is online, 0 isnt
            
                alert(buddyOnline[0]+' is online!');
                //document.getElementById(buddyOnline[0]).src="images/online.bmp";
            
            }else{

                alert(buddyOnline[0]+' is not online!');            
                //document.getElementById(buddyOnline[0]).src="images/offline.bmp";
            
            }//end if
            
        }//end for

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.