使用MVC 2的类似Twitter的自动刷新功能

时间:2011-01-06 23:15:58

标签: asp.net-mvc-2 twitter refresh

如何在MVC 2应用程序中创建twitter自动刷新效果?

感谢

1 个答案:

答案 0 :(得分:0)

您可以使用setInterval javascript函数,该函数允许您定期执行某些代码。然后,您可以向服务器发送AJAX请求,以查看是否有更新并刷新页面的某些部分。以下是如何轮询服务器操作以获取更新的示例:

window.setInterval(function() {
    // this will execute every 5 seconds
    // send an AJAX request
    $.get('/someaction', { }, function(result) {
        // use the result returned from the server
        // to update the DOM
    });
}, 5000);