在Web应用程序中每分钟刷新页面上的数据 [英] Refresh data on page every minute in web app

查看:79
本文介绍了在Web应用程序中每分钟刷新页面上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 


我在ASP.NET中有网络应用程序,我想在页面上显示数据库的最新价值。


目前,来自数据库的数据存储在viewbag中,并且每分钟更新一次。问题是我无法在页面上显示数组中的最新值。 


我有js函数调用此数组并显示最新值。 Js函数在脚本中,我为每分钟设置计时器,但即使它每分钟运行一次,它也没有得到更新的viewbag。如何在没有页面刷新的情况下在脚本中获取更新的viewbag?


问候,


Yerkhan

解决方案

您好Yerkhan,


您可以使用window.setInterval javascript方法定期向服务器发送AJAX请求并刷新相应的部分DOM。例如,如果您想每10秒刷新一次内容:


window.setInterval(function(){

  


< blockquote> .post('@ Url.Action(" someaction"," somecontroller")',function(result){

    


('#results').html(result);

  });

},10 * 1000);


Hi everyone, 

I've got web application in ASP.NET, and I wanted to show latest value from database on page.

Currently, data from database is stored in viewbag and it is updated every minute. The issue is that I cant display latest value from array on page. 

I have js function which calls this array and shows latest value. Js function is in script and I set timer for every minute, but even if it is runs every minute, it didn't get updated viewbag. How I can get updated viewbag in script without page refresh?

Regards,

Yerkhan

解决方案

Hi Yerkhan,

You can use window.setInterval javascript method to send AJAX requests to the server at regular intervals and refresh the corresponding part of the DOM. For example if you wanted to refresh the contents every 10 seconds:

window.setInterval(function() {
   


.post('@Url.Action("someaction", "somecontroller")', function(result) {
       


('#results').html(result);
    });
}, 10 * 1000);


这篇关于在Web应用程序中每分钟刷新页面上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆