3

我的页面上有一个刷新按钮,它将执行一个 asp.net mvc ajax 帖子来更新页面上的一些内容。刷新/更新过程可能会运行很长时间(大约 10-20 秒)。现在用户必须手动点击刷新按钮来触发刷新。我想每 X 分钟自动触发一次刷新。几乎我想触发如下相同的 Ajax 帖子(也可以显示 LoadingElementId)。

<% using (Ajax.BeginForm("Refresh", null, 
                   new {userId=Model.UserId},
                   new AjaxOptions { UpdateTargetId = "UserForm", LoadingElementId = "RefreshingDiv" },
                   null))
               {
            %>

                    <button type="submit">
                        <img src="/zsys/img/icons/refresh.png" alt="Refresh" />
                        Refresh
                    </button>

            <% } %>

如何强制 asp.net mvc ajax 回发?

4

3 回答 3

5

Wyatt Barnett's answer made me try just clicking the Refresh button for the user. And then I used setInterval to trigger the Refresh Button click every 5 minutes:

    <script src="../../scripts/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            setInterval("$('#RefreshFormButton').click()", 300000);
        });
    </script>
于 2009-10-13T17:53:04.717 回答
0

将 RefreshFormButton 放在 id 提交按钮中....那么你就可以让 JS 函数工作了。

于 2010-06-17T20:43:18.317 回答
0

jQuery timer +call $('#form').submit()应该可以解决问题。

于 2009-10-13T15:47:07.303 回答