-1
在特定时间间隔后实时恢复数据我有包含三个面板的页面,包含员工出勤,薪水,生产。我必须通过SignalR实时更新面板。
我毂类通过SignalR
public class MessagesHub : Hub
{
private string ConnectionString = ConfigurationManager.ConnectionStrings["database"].ToString();
[HubMethodName("sendMessages")]
public void SendMessages()
{
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<MessagesHub>();
context.Clients.All.updateMessages();
}
}
在控制器
public ActionResult Panels()
{
...code..
return Partial("_panelData", model);
}
局部页面具有连同数据来显示面板。
在主视图页面(面板),在脚本标签
<script>
$(function() {
// Declare a proxy to reference the hub.
var notifications = $.connection.messagesHub;
//debugger;
// Create a function that the hub can call to broadcast messages.
notifications.client.updateMessages = function() {
getData()
};
// Start the connection.
$.connection.hub.start().done(function() {
getData();
}).fail(function (e) {
alert(e);
});
});
function getData() {
$.ajax({
url: '/PanelController/Panels',
type: 'GET',
dataType: 'html'
}).success(function (result) {
$('.panel').html(result)
}).error(function() {
window.console.log("failure");
});
}
</script>
它工作时的页面加载罚款。但我也希望它每隔1分钟加载一次数据。
在此先感谢
我想在显示数据的getData()函数的回调中每隔1分钟一次 – anand
您应该使用60000来延迟所以;) –
是您的代码将在接下来的1分钟内调用getData()方法interal – anand