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
https://forums.phpfreaks.com/topic/191455-buddy-list-updater/
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
https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009533
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
https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009635
Share on other sites

this works for me:

 


var myString="bwichelt,0#Marijuana,0#nancy,0#Diamondice,0#bamdeadbird,0#VincentKelly,0#test,1";
    
    var myArray=myString.split('#');
    
    for(var i=0; i<myArray.length; i++){
        
        alert(i+': '+myArray[i]);
        
    }//end for

Link to comment
https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009657
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
https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009670
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.