小问题,多分,顶着有份!js定时刷新(以获取是否存在提醒信息),前台代码获取值判断是否执行,可前台代码只在加载时执行一次,如何解决? <% if(!string.isNullorEmpty(hidden1.value)){%><a href="">需审核信息</a><%} %> 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以定时提交表单,也可以写webservice 定时 提交表单用webservice 可以实现的 我嘞个去有两种方法一种是刷新页面的一种是不刷新的(ajax)但基本理论都是一样的你需要在js 写一个或者抄一段定时执行的js要么js 定时耍页面要么js里面加ajax代码,到后台取数据但间隔时间不易过短.否则数据库,服务器可要骂你了 <script type="text/javascript">function fresh(){ 取值判断是否执行代码}setInterval(fresh,2000)//每两秒执行一次fresh方法</script> <script language="javascript" type="text/javascript"> window.onerror = function() { } //出现错误时,不做任何处理 var divTop, divLeft, divWidth, divHeight, docHeight, docWidth, objTimer, i = 0; //关于位置的相关变量 //弹框 function viewMsg() { try { divTop = parseInt(document.getElementById("divMsg").style.top, 10) //div的x坐标 divLeft = parseInt(document.getElementById("divMsg").style.left, 10) //div的y坐标 divHeight = parseInt(document.getElementById("divMsg").offsetHeight, 10)//div的高度 divWidth = parseInt(document.getElementById("divMsg").offsetWidth, 10) //div的宽度 docWidth = document.body.clientWidth; //窗体宽度 docHeight = document.body.clientHeight; //窗体高度 document.getElementById("divMsg").style.top = parseInt(document.body.scrollTop, 10) + docHeight + 10; //设置div的Y坐标 document.getElementById("divMsg").style.left = parseInt(document.body.scrollLeft, 10) + docWidth - divWidth//设置div的X坐标 document.getElementById("divMsg").style.visibility = "visible" //设置div显示 objTimer = window.setInterval("moveDiv()", 5) //设置定时器 } catch (e) { } } //调整大小 ---二次弹层停留时间过短因为i? function resizeDiv() { i += 1; if (i > 500) closeDiv() try { divHeight = parseInt(document.getElementById("divMsg").offsetHeight, 10) //设置div高度 divWidth = parseInt(document.getElementById("divMsg").offsetWidth, 10) //设置div宽度 docWidth = document.body.clientWidth; //获取窗体宽度 docHeight = document.body.clientHeight; //设置窗体高度 document.getElementById("divMsg").style.top = docHeight - divHeight + parseInt(document.body.scrollTop, 10)//设置div的y坐标 document.getElementById("divMsg").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft, 10)//设置div的x坐标 } catch (e) { } } //移动 function moveDiv() { try { if (parseInt(document.getElementById("divMsg").style.top, 10) <= (docHeight - divHeight + parseInt(document.body.scrollTop, 10))) { window.clearInterval(objTimer) objTimer = window.setInterval("resizeDiv()", 20) //调整div的位置和大小 } divTop = parseInt(document.getElementById("divMsg").style.top, 10)//获取y坐标 document.getElementById("divMsg").style.top = divTop - 1//调整div的Y坐标 } catch (e) { } } //关闭层 function closeDiv() { document.getElementById('divMsg').style.visibility = 'hidden'; //将短信息提示层隐藏 if (objTimer) window.clearInterval(objTimer); //清除定时器 } //开始 function beg() { var xmlHttpReq = null; if (window.XMLHttpRequest) { xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlHttpReq != null) { //执行page_load中的方法--》返回新的HiddenField1的值,如果有提醒内容,值为yes xmlHttpReq.open("get", "MainFrame.aspx?s=1&t=" + (new Date).getTime(), false); xmlHttpReq.send(null); //判断是否提醒,为yes则提醒 var isDo = xmlHttpReq.responseText; if (isDo != "") { var arr = isDo.split(','); if (arr[0] == "yes" || arr[1] == "yes" || arr[2] == "yes" || arr[3] == "yes" || arr[4] == "yes") { viewMsg(); if (form.data.value != "") { form.submit(); } } } // if (isDo.indexOf("yes") >= 0) { // document.getElementById("shows").innerHTML = ""; // document.getElementById("shows").innerHTML = '<a href="WebUI/ProcessInit.aspx" target="_blank">您有需审核信息</a><br />'; // viewMsg(); // } } }提交表单应该写在哪里好了?可否提供代码! 首先说一下,你的这种方式好象不太主流啊,定时刷新用服务器端来判断挺怪的。好象现在都是用ajax+webservice了。如果你只是定时刷新当前页也就是相当按f5刷新的那种方式的话,从你的程序来看,你是希望hidden1这个控件的值每新刷新时有可以做为是否输出<a href="">需审核信息</a>的标识,请问你是否在什么地方做了对hidden1的值的变化操作,以此为例,在onload中应当重新设置一下hidden1的值,否则是没有任何用处的。或者是否在设置hidden1值时已经把消息的未阅读标识清除了。 怎么没有人帮忙解答下,请问如果用ajax+webservice如何实现呢?我现在用的是ajax异步调用后台方法! //开始 function beg() { var xmlHttpReq = null; if (window.XMLHttpRequest) { xmlHttpReq = new XMLHttpRequest(); } else if (window.ActiveXObject) { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); } if (xmlHttpReq != null) { //执行page_load中的方法--》返回新的HiddenField1的值,如果有提醒内容,值为yes xmlHttpReq.open("get", "MainFrame.aspx?s=1&t=" + (new Date).getTime(), false); xmlHttpReq.send(null); //判断是否提醒,为yes则提醒 var isDo = xmlHttpReq.responseText; if (isDo != "") { var arr = isDo.split(','); if (arr[0] == "yes") { document.getElementById("Label1").value = '<a href="WebUI/EvaluateManages/remind.aspx" target="_blank">您有评估未填写</a><br />'; } else { document.getElementById("Label1").value = ""; } if (arr[1] == "yes") { document.getElementById("Label2").value = '<a href="WebUI/CheckSend/Check_Send.aspx" target="_blank">您发送的文件已审批结束</a><br />'; } else { document.getElementById("Label2").value = ""; } if (arr[2] == "yes") { document.getElementById("Label3").value = '<a href="WebUI/SendFileManages/send_NewManages/send_New_Manage.aspx" target="_blank">您有新邮件</a><br />'; } else { document.getElementById("Label3").value = ""; } if (arr[3] == "yes") { document.getElementById("Label4").value = '<a href="WebUI/ProcessInit.aspx" target="_blank">您有需审核信息</a><br />'; } else { document.getElementById("Label4").value = ""; } if (arr[4] == "yes") { document.getElementById("Label5").value = '<a href="WebUI/CheckSend/send_NewManages/send_New_Manage.aspx" target="_blank">您有待审批文件</a><br />'; } else { document.getElementById("Label5").value = ""; } if (arr[0] == "yes" || arr[1] == "yes" || arr[2] == "yes" || arr[3] == "yes" || arr[4] == "yes") {//弹出层 viewMsg(); } } }//弹出层内容<div> <asp:Label ID="Label1" runat="server"></asp:Label> <asp:Label ID="Label2" runat="server"></asp:Label> <asp:Label ID="Label3" runat="server"></asp:Label> <asp:Label ID="Label4" runat="server"></asp:Label> <asp:Label ID="Label5" runat="server"></asp:Label></div>何解?何解? setinterval函数定时后台ajax函数 JS有个函数,叫什么来这,给忘了,大概是这个功能,叫什么来着,一下给忘了,time什么来着,你网上查下吧。 如果要定时获取信息,应该有代码setInterval(beg,?),可是只看到了对div操作的setInterval另外setInterval是毫秒数,windows的时间精度也就15毫秒左右,设为100,一秒刷10次应该够了。而对于beg这种服务器请求尽量用setTimeout,因为网络延时无法预计,一般也不应该小于5000,也就是5秒。 我这个SQL语句咋回事 .net读取XML属性,根据属性显示该节点的值 求助(帮我看看这段代码)?????? 新手问题:一个项目的子文件夹如何再添加一个现有的项目 高手请进!关于邮件发送的问题! ???????????如何在richtextbox中将特定字符显示伟超链???????????? 想用ASP.NET做一个与SQL数据库连接的网页,C#和VB.NET哪个更有优势? 导出到数据到Excel的问题 请问哪里有DotNetBar 1.0.0.7可下载? 请问如果我继承了一个类,我如何改写其中的某个方法呢? 关于多线程锁(lock)的疑惑 数据绑定之后 我如何对数据进行处理?
一种是刷新页面的
一种是不刷新的(ajax)
但基本理论都是一样的你需要在js 写一个或者抄一段定时执行的js
要么js 定时耍页面
要么js里面加ajax代码,到后台取数据
但间隔时间不易过短.否则数据库,服务器
可要骂你了
function fresh()
{
取值判断是否执行代码
}
setInterval(fresh,2000)//每两秒执行一次fresh方法
</script>
window.onerror = function() { } //出现错误时,不做任何处理
var divTop, divLeft, divWidth, divHeight, docHeight, docWidth, objTimer, i = 0; //关于位置的相关变量
//弹框
function viewMsg() {
try {
divTop = parseInt(document.getElementById("divMsg").style.top, 10) //div的x坐标
divLeft = parseInt(document.getElementById("divMsg").style.left, 10) //div的y坐标
divHeight = parseInt(document.getElementById("divMsg").offsetHeight, 10)//div的高度
divWidth = parseInt(document.getElementById("divMsg").offsetWidth, 10) //div的宽度
docWidth = document.body.clientWidth; //窗体宽度
docHeight = document.body.clientHeight; //窗体高度
document.getElementById("divMsg").style.top = parseInt(document.body.scrollTop, 10) + docHeight + 10; //设置div的Y坐标
document.getElementById("divMsg").style.left = parseInt(document.body.scrollLeft, 10) + docWidth - divWidth//设置div的X坐标
document.getElementById("divMsg").style.visibility = "visible" //设置div显示
objTimer = window.setInterval("moveDiv()", 5) //设置定时器
}
catch (e) { }
}
//调整大小 ---二次弹层停留时间过短因为i?
function resizeDiv() {
i += 1;
if (i > 500) closeDiv()
try {
divHeight = parseInt(document.getElementById("divMsg").offsetHeight, 10) //设置div高度
divWidth = parseInt(document.getElementById("divMsg").offsetWidth, 10) //设置div宽度
docWidth = document.body.clientWidth; //获取窗体宽度
docHeight = document.body.clientHeight; //设置窗体高度
document.getElementById("divMsg").style.top = docHeight - divHeight + parseInt(document.body.scrollTop, 10)//设置div的y坐标
document.getElementById("divMsg").style.left = docWidth - divWidth + parseInt(document.body.scrollLeft, 10)//设置div的x坐标
}
catch (e) { }
}
//移动
function moveDiv() {
try {
if (parseInt(document.getElementById("divMsg").style.top, 10) <= (docHeight - divHeight + parseInt(document.body.scrollTop, 10))) {
window.clearInterval(objTimer)
objTimer = window.setInterval("resizeDiv()", 20) //调整div的位置和大小
}
divTop = parseInt(document.getElementById("divMsg").style.top, 10)//获取y坐标
document.getElementById("divMsg").style.top = divTop - 1//调整div的Y坐标
}
catch (e) { }
}
//关闭层
function closeDiv() {
document.getElementById('divMsg').style.visibility = 'hidden'; //将短信息提示层隐藏
if (objTimer) window.clearInterval(objTimer); //清除定时器
} //开始
function beg() { var xmlHttpReq = null;
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttpReq != null) {
//执行page_load中的方法--》返回新的HiddenField1的值,如果有提醒内容,值为yes
xmlHttpReq.open("get", "MainFrame.aspx?s=1&t=" + (new Date).getTime(), false);
xmlHttpReq.send(null);
//判断是否提醒,为yes则提醒
var isDo = xmlHttpReq.responseText;
if (isDo != "") {
var arr = isDo.split(','); if (arr[0] == "yes" || arr[1] == "yes" || arr[2] == "yes" || arr[3] == "yes" || arr[4] == "yes") { viewMsg(); if (form.data.value != "") {
form.submit();
}
} }
// if (isDo.indexOf("yes") >= 0) {
// document.getElementById("shows").innerHTML = "";
// document.getElementById("shows").innerHTML = '<a href="WebUI/ProcessInit.aspx" target="_blank">您有需审核信息</a><br />';
// viewMsg();
// }
}
}提交表单应该写在哪里好了?可否提供代码!
好象现在都是用ajax+webservice了。
如果你只是定时刷新当前页也就是相当按f5刷新的那种方式的话,
从你的程序来看,你是希望hidden1这个控件的值每新刷新时有
可以做为是否输出<a href="">需审核信息</a>的标识,请问你是否
在什么地方做了对hidden1的值的变化操作,以此为例,在onload中
应当重新设置一下hidden1的值,否则是没有任何用处的。或者是否在设置
hidden1值时已经把消息的未阅读标识清除了。
我现在用的是ajax异步调用后台方法!
function beg() {
var xmlHttpReq = null;
if (window.XMLHttpRequest) {
xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttpReq != null) {
//执行page_load中的方法--》返回新的HiddenField1的值,如果有提醒内容,值为yes
xmlHttpReq.open("get", "MainFrame.aspx?s=1&t=" + (new Date).getTime(), false);
xmlHttpReq.send(null);
//判断是否提醒,为yes则提醒
var isDo = xmlHttpReq.responseText;
if (isDo != "") {
var arr = isDo.split(',');
if (arr[0] == "yes") {
document.getElementById("Label1").value = '<a href="WebUI/EvaluateManages/remind.aspx" target="_blank">您有评估未填写</a><br />';
} else {
document.getElementById("Label1").value = "";
}
if (arr[1] == "yes") {
document.getElementById("Label2").value = '<a href="WebUI/CheckSend/Check_Send.aspx" target="_blank">您发送的文件已审批结束</a><br />';
} else {
document.getElementById("Label2").value = "";
}
if (arr[2] == "yes") {
document.getElementById("Label3").value = '<a href="WebUI/SendFileManages/send_NewManages/send_New_Manage.aspx" target="_blank">您有新邮件</a><br />';
} else {
document.getElementById("Label3").value = "";
}
if (arr[3] == "yes") { document.getElementById("Label4").value = '<a href="WebUI/ProcessInit.aspx" target="_blank">您有需审核信息</a><br />';
} else {
document.getElementById("Label4").value = "";
}
if (arr[4] == "yes") {
document.getElementById("Label5").value = '<a href="WebUI/CheckSend/send_NewManages/send_New_Manage.aspx" target="_blank">您有待审批文件</a><br />';
} else {
document.getElementById("Label5").value = "";
} if (arr[0] == "yes" || arr[1] == "yes" || arr[2] == "yes" || arr[3] == "yes" || arr[4] == "yes") {
//弹出层
viewMsg();
}
}
}
//弹出层内容
<div>
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:Label ID="Label3" runat="server"></asp:Label>
<asp:Label ID="Label4" runat="server"></asp:Label>
<asp:Label ID="Label5" runat="server"></asp:Label>
</div>何解?何解?
另外setInterval是毫秒数,windows的时间精度也就15毫秒左右,设为100,一秒刷10次应该够了。
而对于beg这种服务器请求尽量用setTimeout,因为网络延时无法预计,一般也不应该小于5000,也就是5秒。