ajax站内短信asp获取代码

关注:929发表于:2018/5/20

<%
var timeout = null; //setInterval函数句柄
var xmlHttp = false; //
//初始化XMLHttpRequest对象
function createXmlHttp(){
    xmlHttp = false;
    if (window.ActiveXObject) {
        try {xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");} 
        catch (e) {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
    }else if (window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest();}
}
//异步调用页面获取结果timestamp为了不让浏览器缓存结果
function sendRequest(){
    createXmlHttp();
    var url = "/message/getmessage.asp教程?timestamp=" + new Date().getTime();
    if (!xmlHttp) {
        alert("XMLHttpRequest is not Create!");
    }
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = function(){//回调函数开始
        var tag = document.getElementById("newmsg");
        tag.innerHTML = "";
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            if (xmlHttp.responseText>0) {
               tag.innerHTML= "<img src='/images/msg.gif' width='16' height='15' /> 您有[ "+xmlHttp.responseText+" ]封未读邮件";
            }else{
               tag.innerHTML="";    
            }
        }
    }//回调函数结束
xmlHttp.send(null);
}

//开始自动刷新
function update(){
timeout = window.setInterval("sendRequest()", 10000);//设定10秒调用一次update页面
}
//停止自动刷新
function Stopupdate(){
if (timeout != null) {
window.clearInterval(timeout);
}
}%>

在线咨询

点击开始 QQ咨询
TOP
{"error":401,"message":"site error"}