110,536
社区成员
发帖
与我相关
我的任务
分享
function loadXMLDoc(type,sendHtml)
{
var xmlhttp;
if (username != null)
{
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("message-take").innerHTML = xmlhttp.responseText;
}
}
if (type == "get") { //取得数据信息
xmlhttp.open("POST", "http://127.0.0.1/receive.aspx?type=get" + "&uid=" + escape(username) + "&taker=" + document.getElementById('take-class').value, true); //传递页面
xmlhttp.send();
} else if (type == "send") { //发送数据信息
var nowTime = new Date().getTime();
xmlhttp.open("POST", "http://127.0.0.1/receive.aspx?type=send×tamp=" + nowTime + "&uid=" + escape(username) + "&taker=" + document.getElementById('take-class').value, true);
sendHtml = html2Escape(sendHtml); //转码,能显示html格式
var queryString = "msg=" + escape(sendHtml); //发送的内容
xmlhttp.setRequestHeader("Content-Length", queryString.lenght); //发送的内容长度
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); //发送的内容编码
xmlhttp.send(queryString);
}
ScrolltoBottom(); //滚动保持最底部
setTimeout("loadXMLDoc('get','')", 1000); //1秒执行一次
}
}
JS定时器:
1、window.setTimeout(function(){},3000)
延迟3秒执行
2、window.setInterval(function(){},3000)
也叫重复器,每3秒重复相同的事件
关闭定时器:
var timer = window.setTimeout(function(){
window.clearTimeout("timer");
},3000);
var timer = window.setInterval(function(){
window.clearInterval("timer");
},3000);
你写的[code=javascript]....<%=Getstr()%>";
这类代码并不会访问 asp.net 端的 Getstr 函数。你可以打开浏览器看看这个地方的 html 源代码就一下在明白了,我相信你有这个基础,可以一下子看懂问题出在哪里。“页面生命周期”机制,在页面 Render 的时候一行性地把 Getstr 函数的值放到 html 字符输出流中,仅仅一次。