I’m using this code to refresh a div every 5000 milliseconds: (and update the title as well)
<script type="text/javascript">
function changeTitle() {
var title = $('.subjectContainer').html();
document.title = title+' | WeeBuild Customer Support';
}
$(document).ready(function() {
$(".subjectContainer").load("subject.php?ticket=<?php echo $_GET[ticket]; ?>");
var refreshId = setInterval(function() {
$(".subjectContainer").load("subject.php?ticket=<?php echo $_GET[ticket]; ?>");
changeTitle();
}, 5000);
$.ajaxSetup({ cache: false });
});
</script>
The page being loaded is just one line of text that is retrieved from the database.
See here: http://weebuild.heliohost.org/employee/subject.php?ticket=5156869
That’s the page being loaded. When a user changes the subject of a ticket, I am making it stay updated so it will change for everyone viewing the ticket without refreshing the page.
But, will this overload the server I’m on?
Instead of constantly polling your server, which will indeed introduce a lot of overhead, look into long polling instead. From your code it looks like you are just trying to update the status of a help ticket – which I assume doesn’t happen every five seconds. Long polling basically sends a data request out to the server which can then respond at its leisure. Giving you the convenience of only updating when something actually changed. And also not pinging your server incessantly.