您的位置:首页 > 编程语言 > C#

C# MVC框架定时刷新页面

2018-01-23 11:36 1101 查看
承接上篇转载文章,

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);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  自动刷新