Auto update div content loaded by jquery includes ajax call

I am loading the output from now_playing.php

(shout is now playing content) using jQuery include ajax call like sugested here and it works well.

My code:

<script>
$(function(){
    $("#now_playing").load("now_playing.php");
});
</script>

<div id="now_playing"></div>

      

I just need the content of the output div to update every 5 seconds or so. What code can I add to a script or div for this? Thank!

+3


source to share


4 answers


You can do this: Put yours load()

in a function, then use setInterval

to call it every 5 seconds.



function loadNowPlaying(){
  $("#now_playing").load("now_playing.php");
}
setInterval(function(){loadNowPlaying()}, 5000);

      

+4


source


You can use setInterval

for this. how

setInterval(function(){
    $("#now_playing").load("now_playing.php");
    ...
}, 5000);

      



It will do the download now_playing.php

and make the other stuff you want every 5 seconds (5000 milliseconds)

+2


source


try doing it with setInterval ():

$(function(){
   setInterval(function(){$("#now_playing").load("now_playing.php")},5000);
}

      

0


source


Found out the suggestions of Magicprog.fr, augustoccesar and Edan Feiles and decided that the Magicprog.fr solution is best because it loads output_playing.php first and then just updates it at a given interval:

<script>
function loadNowPlaying(){
  $("#now_playing").load("now_playing.php");
}
setInterval(function(){loadNowPlaying()}, 5000);
</script>

      

Many thanks for the help:)

0


source







All Articles