I’m developing a dashboard using ASP.NET MVC3 and need to have two divs which contain a partial view each, refresh the data at different intervals.
So, div “results” that contains “PartialOverview” refresh at 1 minute, and div “rain” that contains “PartialOverviewRainfall” refresh at 15 minutes.
The index page that references the two partial views/divs is where I have put the JQuery code. It works when I just use one div, the “PartialOverview” as that is the bulk of the display, but I can’t seem to get the code right to include another div.
Here’s my code:
<script type="text/javascript">
$(document).ready(function() {
$("#results").load("/EDM/Index");
setInterval(function() {
$("#results").load("/EDM/Index");
}, 60000); //Refreshes every 60 seconds
$.ajaxSetup({ cache: false });
});
</script>
<div id="rain">
@Html.Partial("PartialOverviewRainfallList")
</div>
<div id="results">
@Html.Partial("PartialOverviewList")
</div>
Is there a way to adapt the javascript code to include the two divs?
You could add another
setIntervalfor the other partial:or try to use a more generic solution (using for example HTML5
data-*attributes):and then:
Now you could even put this into a separate javascript file where it belongs.