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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.