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);
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);
相关文章推荐
- response实现案例之页面定时刷新
- Ajax实现不刷屏的前提下实现页面定时刷新
- C# 刷新页面浏览次数(点击量)+1
- C#中刷新页面的方式
- web页面定时刷新
- php长期定时刷新一个页面
- 在页面中定时处理C#程序
- 定时刷新页面时不让页面闪烁
- 定时刷新页面
- 如何定时刷新页面
- servlet相关知识,使用servlet实现定时刷新,实现页面登录次数统计
- JS定时刷新页面
- ajax定时刷新页面
- JS定时刷新页面及跳转页面的方法
- 一个无刷新效果定时自动更新页面的例子(ASP.NET2.0-应用xmlhttp)
- js定时刷新局部页面及动态加载页面后事件处理
- jQuery实现AJAX定时刷新局部页面实例
- 定时请求php 后台 AJAX 请求,在页面中倒计时,和显示刷新时间
- 定时弹出提示信息 不刷新页面。
- js页面刷新之实现定时刷新(定时器,meta)