Reputation: 93
I currently have a javascript code that should update my partial view every 3 seconds. But it doesn't work for some reason, the timer it self works.
<script>
setInterval(function () {
var obj = document.getElementById("menubar");
obj.innerHTML = "@Html.Partial("/Views/Menu.cshtml")";
}, 3000);
</script>
This is my code, i am new to javascript. So i have no idea what's wrong. I tried to show my session as well, didn't work either.
Any help?
Upvotes: 0
Views: 1796
Reputation: 1887
create an action like below.
public ActionResult Menu()
{
return View();
}
better to keep your partial view in shared folder.
your javascript.
<script>
setInterval(function () {
$("#menubar").empty().load('/{controller_name}/Menu');
}, 3000);
</script>
replace {controller_name} with the actual controller name.
Problem with your code was you are sticking the output of partial view into your javascript so everytime setIntervel was running it was picking the output from javascript not requesting it from your server.
Upvotes: 2