shane18 Posted February 9, 2010 Share Posted February 9, 2010 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 More sharing options...
RussellReal Posted February 9, 2010 Share Posted February 9, 2010 dude how are you making a function inside of a function? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009313 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 lol ur right oops Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009519 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 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 More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 What does the error console say? load ur page, clear the console, reload ur page, and post what it says the errors are. Assuming you are using chrome or ff that is, and you should be. Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009537 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 I use Firefox , and it says Useless setTimeout call... btw remember im new to javascript... im better at php then javascript... so im sorta clueless Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009538 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 What is exactly the error? Do you have a link to the site? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009600 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 http://www.oddim.com/ use test/test to login... it is not fully complete yet... Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009602 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 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 More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 my split is going character by character... why? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009642 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 ohh im using the split wrong.... whats the javascript version of the php explode? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009645 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 implode? are you sure you wanna turn an array into a string? the php version turns {1 => '1', 2=>'2') into 12.. what format is your response in? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009650 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 I want to turn a string into a array... bwichelt,0#Marijuana,0#nancy,0#Diamondice,0#bamdeadbird,0#VincentKelly,0#test,1 For example: I want BUDDY[0] to be bwichelt,0 and BUDDY[1] to be Marijuana,0 ... how do I do this? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009653 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 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 More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 how can I write that using the for in loop? or is ur way better? Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009659 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 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 More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 I changed the actions to alerts, so u can debug btw. Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009675 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 ooohhhh you have to do VARIABLE = VARIABLE.split("x"); not just VARIABLE.split("x").... im such a noob at javascript.... -I didn't see your other 2 post before I posted this... Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009676 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 I got it to work... but I got a question... if you do if(VARIABLE){ in javascript... 0 should = false and 1 should = true right? or can u only do that type of if in php if($TEST){ Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009682 Share on other sites More sharing options...
seventheyejosh Posted February 9, 2010 Share Posted February 9, 2010 I know what you mean, and it may work like that, but I always just do >0 or <1 in my code. Just try it out i guess. Even though it is a string, javascript may eval it as a boolean. Also congrats on getting it up and running Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009710 Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 thanks for all the help Link to comment https://forums.phpfreaks.com/topic/191455-buddy-list-updater/#findComment-1009773 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.