I'm working on an application that uses asp.NET mvc3. I created a partial view, and I call this partial view in a view, so that I can update a div without reloading the page. I use setTimeout (but I also tried setInterval) to define the refreshing time. The problem is that it does not work, it refreshes the div randomly, not following the time I set, and there is no logic that I can understand in it, sometimes it refreshes it twice, sometimes it waits, but never longer then the time I set. This is the code of the partial view. In the View I just call the partial view.
<script type="text/javascript">
var st;
function updateDiv() {
st = null;
clearTimeout(st);
console.log("posting");
$.post('@Url.Action("RefreshSelfUpdatingPartial")', function (data) {
$('#SelfUpdatingPartialDiv').hide().slideDown("slow").html(data);
//wait 15 seconds
st = setTimeout(updateDiv, 15000);
});
}
updateDiv();
</script>
<div id="SelfUpdatingPartialDiv">
test
</div>