Jump to content

[SOLVED] live update .. ajax??


severndigital

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/180563-solved-live-update-ajax/
Share on other sites

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

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.