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();"> Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 lol ur right oops Quote Link to comment 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... Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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... Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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... Quote Link to comment 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){ Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
shane18 Posted February 9, 2010 Author Share Posted February 9, 2010 thanks for all the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.