日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ajax联系人数,setInterval定时调用ajax实现在线人数统计

發(fā)布時間:2024/1/23 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ajax联系人数,setInterval定时调用ajax实现在线人数统计 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

index頁面把onLineCount.jsp給include進(jìn)來,onLineCount.jsp每隔一段時間刷新一次從數(shù)據(jù)庫中統(tǒng)計數(shù)據(jù),很顯然這個方法非常的錯誤,onLineCount.jsp每次刷新的同時index整個頁面也要刷新,首頁數(shù)據(jù)量大的情況下肯定不行。而且還出現(xiàn)了一個我更郁悶的問題

:用戶a登錄后頁面顯示a的相關(guān)信息,用戶b

登錄后應(yīng)該顯示b的相關(guān)信息,如果把刷新的間隔時間設(shè)的短假如10秒鐘,那么在服務(wù)器反映慢的情況下,如果a

已經(jīng)登錄并顯示a的內(nèi)容,但是剛好在b登錄的時候,a頁面正好刷新,等b登陸成功后b的頁面顯示b的信息,但這個時候a的頁面也顯示了b的信息,如果我把這個間隔的時間設(shè)長,加入1分鐘,即使服務(wù)器再慢1分鐘應(yīng)該反映的過來吧,這樣就沒有出現(xiàn)亂套的問題,如果間隔時間為10秒,服務(wù)器反映夠快,也不會出現(xiàn)亂套的情況。

于是還得想辦法,ajax以前經(jīng)常聽說,實際中也沒用過那么就用這個試一下,結(jié)果發(fā)現(xiàn)還真的像傳說中的那么好用

Count.jsp

language="java" %>

import="cn.sh.guanghua.mediamex.common.CountServlet"%>

import="cn.sh.guanghua.mediamex.db.dataunit.MonitorServer"%>

import="cn.sh.guanghua.mediamex.common.Db"%>

import="java.util.List"%>

import="cn.sh.guanghua.monitor.SnmpValueObject"%>

import="java.util.Hashtable"%>

import="cn.sh.guanghua.mediamex.common.OnlineCounter"%>

long? monitorServer_Id=1;

MonitorServer monitorServer=(MonitorServer)

Db.monitorServer().getObject(monitorServer_Id);

String strIp;

String strCommunity;

long port;

long type;

long timeout;

long version;

strIp=monitorServer.getMonitorServerIp();

strCommunity=monitorServer.getMonitorServerCommunity();

port=monitorServer.getMonitorServerSnmpPort();

type=monitorServer.getMonitorServerType();

timeout=monitorServer.getMonitorServerTimeout();

version=monitorServer.getMonitorServerVersion();

List

result=Db.monitorItem().getSnmpValue(type,port,strIp,strCommunity,version,timeout);

SnmpValueObject snmp=null;

//onlineUsercount

// int

onlineUserCount=OnlineCounter.getOnline();

int

onlineUserCount=Db.sivaUsers().geOnlineCount();

%>

var

getOnline=setInterval("send_request()",2000);

var http_request = false;

function send_request()

{//初始化、指定處理函數(shù)、發(fā)送請求的函數(shù)

http_request = false;

//開始初始化XMLHttpRequest對象

if(window.XMLHttpRequest) { //Mozilla

瀏覽器

http_request = new XMLHttpRequest();

if (http_request.overrideMimeType)

{//設(shè)置MiME類別

http_request.overrideMimeType('text/xml');

}

}

else if (window.ActiveXObject) { //

IE瀏覽器

try {

http_request = new

ActiveXObject("Msxml2.XMLHTTP");

} catch (e)

{

try {

http_request = new

ActiveXObject("Microsoft.XMLHTTP");

} catch (e)

{}

}

}

if (!http_request) { //

異常,創(chuàng)建對象實例失敗

window.alert("不能創(chuàng)建XMLHttpRequest對象實例.");

return false;

}

http_request.onreadystatechange

= processRequest;

//

確定發(fā)送請求的方式和URL以及是否同步執(zhí)行下段代碼

http_request.open("post",

'getCount.jsp',

true);

http_request.send(null);

}

// 處理返回信息的函數(shù)

function processRequest()

{

if

(http_request.readyState == 4) { // 判斷對象狀態(tài)

if (http_request.status == 200) { //

信息已經(jīng)成功返回,開始處理信息

//alert(http_request.responseText);

onlineCount.innerHTML=http_request.responseText;

} else { //頁面不正常

alert("您所請求的頁面有異常。");

}

}

}

文章轉(zhuǎn)載請注明來源。新輝網(wǎng)主頁 > 網(wǎng)頁基礎(chǔ) > Javascript/Ajax >

標(biāo)題:setInterval定時調(diào)用ajax實現(xiàn)在線人數(shù)統(tǒng)計

地址:http://www.a55.com.cn/a/1662.html

關(guān)鍵詞:setInterval定時調(diào)用ajax實現(xiàn)在線人數(shù)統(tǒng)計_無夢

總結(jié)

以上是生活随笔為你收集整理的ajax联系人数,setInterval定时调用ajax实现在线人数统计的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。