使用AJAX刷新Asp.net MVC页面

Asp.net MVC page refresh sing AJAX

本文关键字:MVC 页面 net Asp AJAX 刷新 使用      更新时间:2023-09-26

我正在asp.net MVC上工作,在这里我使用了highcharts,将显示来自仪表的数据。数据是每15-20秒后,所以我想重新加载/刷新页面后,每15/20秒使用ajax。

我该怎么做呢?

这是我的url Home/MultiGraph

如果您想要自动刷新页面,只需使用这个

<meta http-equiv="refresh" content="5" >

其中content = "5"为等待时间,即5秒。它会在5秒后刷新你的页面。

,或者试试这个。

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <title>Ajax Page</title>
    <script>
    setInterval(function () { autoloadpage(); }, 30000); // it will call the function autoload() after each 30 seconds. 
    function autoloadpage() {
        $.ajax({
            url: "URL of the destination page",
            type: "POST",
            success: function(data) {
                $("div#wrapper").html(data); // here the wrapper is main div
            }
        });
    }
    </script>
</head>
<body>
<div id="wrapper">
contents will be changed automatically. 
</div>

另一个尝试,只要插入这段代码在页面的任何地方:

<script type="text/javascript">
  setTimeout(function(){
  location = ''
 },60000)
</script>