I'm trying to use JQuery
to reload a PartialView
in an ASP.Net MVC
application.
My code:
<div class="partial">
@Html.Action("GetRemainingSeats", "Layout")
</div>
<script src="@Url.Content("~/Scripts/jquery-1.10.2.min.js")"></script>
<script type="text/javascript">
setTimeout(
$(function () {
setInterval(function () { $('#partial').load('@Html.Action("GetRemainingSeats", "Layout")'); }, 5000)
}), 6000);
</script>
The partial view is loaded correctly, but immediately after that, it will again execute the action, without waiting for the setTimeout
function timer to elapse. After that it will stop doing anything.
Edit:
Inside the PartialView
there is a table with shows in a cinema together with how many seats are left for each show. So I want that to update very couple of seconds so the employees can see how many seats are left for a show.
I'm using the timeout and setinterval
function because on pageload
the action is called. After that I want it to wait a couple of seconds before starting the interval