我使用的是Asp.net MVC,我希望我的部分视图在间隔时间内刷新,直到我做出不相关的Ajax请求,然后停止。在Ajax请求后setInterval停止
下面是一些简化的剪辑来说明问题。
在AjaxRefresh.js:
function ajaxRefresh()
{
var f = $("#AjaxForm");
$("#AjaxLoading").show();
$.post(f.attr("action"), f.serialize(), function (context) {
$("#AjaxDiv").html(context);
$("#AjaxLoading").hide();
});
}
setInterval(ajaxRefresh, 1000);
中的Index.aspx:
<script type="text/javascript" src="../../Scripts/AjaxRefresh.js"></script>
<div id="AjaxDiv">
<% Html.RenderPartial("Computers", Model, ViewData); %>
</div>
而这Computers.ascx:
<% Ajax.BeginForm("Index", new { groupName = Model.Name }, new AjaxOptions() { HttpMethod = "Post", LoadingElementId = "AjaxLoading", UpdateTargetId = "AjaxDiv" }, new { id = "AjaxForm" }); Html.EndForm();%>
<%= Ajax.ActionLink("Send", "Index", new { groupName = Model.Name, data="blah" },
new AjaxOptions() { HttpMethod="Post", LoadingElementId="AjaxLoading", UpdateTargetId="AjaxDiv" }) %>
如果单击 “发送” 链接,一切仍然有效,但页面会自动刷新。 我试过订阅ajax事件,但是Sys.WebForms.PageRequestManager.getInstance()是未定义的。
我与setInterval有完全相同的问题。我已经尝试过使用setTimeout,就像你没有运气一样。我的setInterval正在调用一个执行POST的函数,每次都能正常工作,直到我触发一个执行不同POST的单击事件时......第二个POST触发时,setInterval停止。你有没有找到一种方法来使这个工作? – Dragn1821 2011-09-09 14:30:55