Reputation: 313
I have a background process that is aggregating information for me, and I would like to make it so that the web page refreshes the containing div
every 10 seconds. Unfortunatley, most of the articles I am coming across are for using JS and/or ajax with forms.
I'm trying to do something more along the lines of...
<script type="text/javascript">
$(function() {
check_articles("new_articles()", 10000);
});
function new_articles(){
document.getElementById("articles").innerHTML="
<?php
$this->select_articles();
?>";
}
</script>
<div id="articles" onload="check_articles(); return false;">
Article's contents.
</div>
I really need to find the time to brush up on my JS... Anyway, the concept is there. The question is, is there a better (more effective / efficient) way to do this?
I've been up for nearly 24 hours so I'm going to play with this more tomorrow. Nonetheless, I look forward to hearing your guy's feedback and insight, as always.
Thanks.
Upvotes: 0
Views: 99
Reputation: 6002
make an ajax call to the server script on regular interval (1000 milli seconds)
function callServer(){
setInterval(function(){
$.ajax({
url: "server.php/select_articles",
success:function(reponse) {
$("#articles").html(response);
}
});
},1000);
}
Happy Coding :)
Upvotes: 1