severndigital Posted November 6, 2009 Share Posted November 6, 2009 I have a PHP based website that has a little piece of code that looks at database and diplays an image based on the database query. nothing fancy just like this //paraphrased this code just do you get the idea, my actual code works. $query = "SELECT status FROM status_monitor ORDER BY id"; if($query == 1){ <img src="images/active.png"> }else{ <img src="images/stopped.png"> } I would like the graphic to change automatically without refreshing the page if the status changed. Can i do this using ajax? if so, can someone point me in the right direction? I have done ajax calls where i am switching the content of div or span using the onclick but i'm not sure how to do it without user interaction of some kind. i would also like to keep from refreshing the whole page if possible. thanks in advance, -C Quote Link to comment https://forums.phpfreaks.com/topic/180563-solved-live-update-ajax/ Share on other sites More sharing options...
severndigital Posted November 6, 2009 Author Share Posted November 6, 2009 ok so i got it figured out to a point .. i need to use setInterval(). but why is this simple example not working properly? <script language="Javascript"> function livestatus(){ var output = '#FF99CC'; document.getElementById('testing').style.color = output; } var time=5; var interval = time * 1000; var timer setInterval("livestatus()",interval); </script> <div id="testing" style="color:#03F">SOME STUFF HERE SHOULD CHANGE COLOR!</div> any help would be great. thanks, C Quote Link to comment https://forums.phpfreaks.com/topic/180563-solved-live-update-ajax/#findComment-952731 Share on other sites More sharing options...
severndigital Posted November 6, 2009 Author Share Posted November 6, 2009 Nevermind .. i got it working Quote Link to comment https://forums.phpfreaks.com/topic/180563-solved-live-update-ajax/#findComment-952743 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.