简体   繁体   English

ASP.Net MVC如何每10秒调用一次操作方法

[英]ASP.Net MVC how to invoke the action method every 10 seconds

Sorry if this is a silly question. 抱歉,这是一个愚蠢的问题。

I have a simple MVC action method which retrieves data from database. 我有一个简单的MVC操作方法,可以从数据库中检索数据。 I would like to call this action method every 10 seconds to get new data. 我想每10秒调用一次此操作方法以获取新数据。

Basically need a way to refresh the index page, thereby calling the index method, which gets the latest data from db and display it here. 基本上需要一种刷新索引页的方法,从而调用index方法,该方法从db获取最新数据并在此处显示。

Can anyone help how to do this in asp.net 4.5 mvc EF code first. 谁能帮助您首先在asp.net 4.5 mvc EF代码中执行此操作。

This is a simple mvc application. 这是一个简单的mvc应用程序。

Thanks 谢谢

If you`re sure that it is what you want to do, you can achieve it using jquery: 如果确定要执行此操作,则可以使用jquery来实现:

$(document).ready(function () {
    setInterval(function () {
        callMyAPI();
    }, 10000);
});

function callMyAPI() {
    return $.ajax({
        url: 'YOUR_URL',
        type: "GET",
        dataType: "JSON"
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM