C# MVC框架定时刷新页面

承接上篇转载文章,

public class BMController : Controller
    {
        private DBContext db = new DBContext();
        //IE窗体监控器 
        private IE_Watcher _ieWatcher = null;
  


        public ActionResult Index()
        {           
            //实例化对象,将窗体对象作为参数传入,为什么呢? 
            _ieWatcher = new IE_Watcher();//this
            _ieWatcher.UrlText = new UrlHistory("c:\\urlhistory.txt");
            //获取所有已打开的IE窗体 
            IList windows = _ieWatcher.GetOpenedWindows();
            //IE_Item item=new IERefersh.IE_Item ();
            foreach (SHDocVw.InternetExplorer ie in windows)
            {
                //在这里加入自定义对象哦!!! 
                if (ie.LocationURL == "http://localhost:64674/")
                    _ieWatcher.ListenWindow(new IE_Item(ie).IE);
            }        
           
            return View(db.BMZD.ToList());
        }
       
        public ActionResult IsRefresh()
        {
            _ieWatcher = new IE_Watcher();//this
            _ieWatcher.UrlText = new UrlHistory("c:\\urlhistory.txt");
            string time = _ieWatcher.UrlText.ReadHistory();
            DateTime st = DateTime.Parse(time);
            TimeSpan tspan = DateTime.Now - st;
            double second = tspan.TotalSeconds;
            int Tag = 0;
            if (second > 30)
                Tag = 1;
            return Content(Tag.ToString());
        }

}

对应JS文件

var numberItem = -1;
function DisplayCreat() {
    $.ajax({
        type: "Get",
        url: "/BM/IsRefresh",
        data: "person=12",
        async: false,
        cache: false,
        success: function (msg) {
            if(msg=="1")//更新
                window.location.reload();//重新加载页面
        },
        error: function (e) {
            numberItem = 0;
        }


    });
}
setInterval(function () {
    DisplayCreat();
}, 5000);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值