通过AJAX调用ASP.NET MVC控制器明确 [英] Calling ASP.NET MVC Controller explicitly via AJAX
本文介绍了通过AJAX调用ASP.NET MVC控制器明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道,我可以用下面这段code刷新一个div:
I know that I can use following piece of code to refresh a div:
<%=Ajax.ActionLink( "Update", "Administration", new AjaxOptions { UpdateTargetId = "grid", LoadingElementId = "grid-wait" } ) %>
不过,这将创建一个链接;用户必须点击它来获取视图刷新。
But this creates a link; user will have to click on it to get the view refreshed.
我怎样才能使它自动的,也就是说,像说,如果我想在网格每五秒钟之后被刷新?
How can I make it automatic, i.e., like say if I want the grid to be refreshed after every five seconds?
推荐答案
试试这个:
<p id="CurrentDateTime"></p>
<script src="../../Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
window.setInterval(updateDateTime, 5000);
function updateDateTime() {
$.get("GetCurrentDate?rnd=" + Math.random(1000), {}, function (r) {
$("#CurrentDateTime").html(r);
}, "text");
}
</script>
public ActionResult GetCurrentDate()
{
return Content(DateTime.Now.ToString("U"));
}
这篇关于通过AJAX调用ASP.NET MVC控制器明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文